DCCL v3
field_codec_message_stack.h
1 // Copyright 2009-2017 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (for 2013-)
3 // Massachusetts Institute of Technology (for 2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Dynamic Compact Control Language Library
8 // ("DCCL").
9 //
10 // DCCL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // DCCL is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with DCCL. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef DCCLFIELDCODECHELPERS20110825H
23 #define DCCLFIELDCODECHELPERS20110825H
24 
25 #include "dccl/common.h"
26 
27 namespace dccl
28 {
29  class FieldCodecBase;
30  enum MessagePart { HEAD, BODY, UNKNOWN };
31 
33  namespace internal
34  {
35  //RAII handler for the current Message recursion stack
37  {
38  public:
39  MessageStack(const google::protobuf::FieldDescriptor* field = 0);
40 
41  ~MessageStack();
42 
43  bool first()
44  { return desc_.empty(); }
45  int count()
46  { return desc_.size(); }
47 
48  void push(const google::protobuf::Descriptor* desc);
49  void push(const google::protobuf::FieldDescriptor* field);
50  void push(MessagePart part);
51 
52  static MessagePart current_part() { return parts_.empty() ? UNKNOWN : parts_.back(); }
53 
54  friend class ::dccl::FieldCodecBase;
55  private:
56  void __pop_desc();
57  void __pop_field();
58  void __pop_parts();
59 
60  static std::vector<const google::protobuf::Descriptor*> desc_;
61  static std::vector<const google::protobuf::FieldDescriptor*> field_;
62  static std::vector<MessagePart> parts_;
63  int descriptors_pushed_;
64  int fields_pushed_;
65  int parts_pushed_;
66  };
67  }
68 }
69 
70 #endif
Dynamic Compact Control Language namespace.