My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
IdlHandler.h
Go to the documentation of this file.
1 // $Id: IdlHandler.h,v 1.1.1.1 2009/07/06 23:57:22 eml Exp $
2 
3 #ifndef GCP_IDL_IDLHANDLER_H
4 #define GCP_IDL_IDLHANDLER_H
5 
16 #include <iostream>
17 #include <list>
18 #include <vector>
19 
20 #include "idl_export.h"
21 
22 #include "gcp/util/common/DataType.h"
23 #include "gcp/util/common/MonitorDataType.h"
24 
25 namespace gcp {
26  namespace idl {
27 
28  //------------------------------------------------------------
29  // A class for managing structure definitions
30  //------------------------------------------------------------
31 
32  class IdlStructDef {
33  public:
34 
35  struct IdlStructTag {
36  std::string name_;
37  std::vector<unsigned> dims_;
38  void* type_;
39  IdlStructDef* def_;
40 
41  IdlStructTag(const IdlStructTag& tag) {
42  *this = (IdlStructTag&) tag;
43  }
44 
46  *this = (IdlStructTag&) tag;
47  }
48 
49  void operator=(const IdlStructTag& tag) {
50  *this = (IdlStructTag&) tag;
51  }
52 
53  void operator=(IdlStructTag& tag) {
54  name_ = tag.name_;
55  dims_ = tag.dims_;
56  type_ = tag.type_;
57  if(tag.def_)
58  def_ = new IdlStructDef(*tag.def_);
59  else
60  def_ = 0;
61  };
62 
63  IdlStructTag() {
64  type_ = 0;
65  def_ = 0;
66  };
67 
68  virtual ~IdlStructTag() {
69  if(def_)
70  delete def_;
71  };
72  };
73 
74  IdlStructDef();
75  IdlStructDef(const IdlStructDef& def);
77 
78  // Assignment operator
79 
80  void operator=(const IdlStructDef& def);
81  void operator=(IdlStructDef& def);
82 
83  virtual ~IdlStructDef();
84 
85  // Add a simple data member to a structure
86 
87  void addDataMember(std::string name,
89  unsigned len=1);
90 
91  void addDataMember(std::string name,
93  std::vector<unsigned int>& dims);
94 
95  void addDataMember(std::string name,
96  gcp::util::DataType::Type dataType,
97  unsigned len=1);
98 
99  void addDataMember(std::string name,
100  gcp::util::DataType::Type dataType,
101  std::vector<unsigned int>& dims);
102 
103  void addDataMember(std::string name,
104  int idlType,
105  std::vector<unsigned int>& dims);
106 
107  // Add a substructure member to this structure
108 
109  IdlStructDef* addStructMember(std::string name,
110  IdlStructDef& def,
111  std::vector<unsigned int>& dims);
112 
113  IdlStructDef* addStructMember(std::string name,
114  IdlStructDef& def,
115  unsigned len=1);
116 
117  IdlStructDef* addStructMember(std::string name);
118 
119  IdlStructDef* getStructMember(std::string name, bool create=false);
120 
121  // Convert a list of tags into a structure definition
122 
123  IDL_StructDefPtr getStructDefPtr();
124 
125  // Convert from our internal tag representation to the array
126  // required by IDL
127 
128  IDL_STRUCT_TAG_DEF* createIdlTagArray();
129 
130  // Free a tag array previously allocated by createIdlTagArray()
131 
132  void deleteIdlTagArray(IDL_STRUCT_TAG_DEF* tags);
133 
134  // Create an IDL struct definition
135 
136  IDL_StructDefPtr makeStruct();
137 
138  void printTags();
139 
140  friend std::ostream& operator<<(std::ostream& os, IdlStructDef& def);
141 
142  public:
143 
144  std::list<IdlStructTag> tags_;
145 
146  private:
147 
148  std::vector<IdlStructDef*> structs_;
149 
150  IDL_StructDefPtr sDefPtr_;
151  };
152 
153  // A class for managing IDL data structures
154 
155  class IdlHandler {
156  public:
157 
158  // Constructor.
159 
160  IdlHandler(IDL_VPTR vptr);
161 
162  // Destructor.
163 
164  virtual ~IdlHandler();
165 
166  // Create a numeric array
167 
168  static IDL_VPTR createArray(std::vector<unsigned>& dims,
169  gcp::util::DataType::Type dataType,
170  char** data);
171 
172  // Create a string
173 
174  static IDL_VPTR createString(std::string str);
175 
176  // Given a structure definition, create a structure
177 
178  static IDL_VPTR createStructure(IdlStructDef& def, std::vector<unsigned>& dims, char** data=0);
179  static IDL_VPTR createStructure(IdlStructDef& def, unsigned len=1, char** data=0);
180 
181  // Utility function to return the IDL type code that corresponds
182  // to the DataType code
183 
184  static int idlTypeOf(gcp::util::DataType::Type dataType);
185  static int idlTypeOf(gcp::util::MonitorDataType& dataType);
186  static int idlTypeOf(gcp::util::MonitorDataType::FormatType formatType);
187 
188  private:
189 
190  IDL_VPTR vptr_;
191 
192  }; // End class IdlHandler
193 
194  } // End namespace idl
195 } // End namespace gcp
196 
197 
198 
199 #endif // End #ifndef GCP_IDL_IDLHANDLER_H
Definition: IdlHandler.h:32
virtual ~IdlHandler()
Definition: IdlHandler.cc:24
IDL_STRUCT_TAG_DEF * createIdlTagArray()
Definition: IdlHandler.cc:413
Definition: MonitorDataType.h:16
static IDL_VPTR createStructure(IdlStructDef &def, std::vector< unsigned > &dims, char **data=0)
Definition: IdlHandler.cc:68
void operator=(const IdlStructDef &def)
Definition: IdlHandler.cc:212
static IDL_VPTR createString(std::string str)
Definition: IdlHandler.cc:50
IdlStructDef * getStructMember(std::string name, bool create=false)
Definition: IdlHandler.cc:334
IDL_StructDefPtr getStructDefPtr()
Definition: IdlHandler.cc:364
void deleteIdlTagArray(IDL_STRUCT_TAG_DEF *tags)
Definition: IdlHandler.cc:470
IDL_StructDefPtr makeStruct()
Definition: IdlHandler.cc:390
static IDL_VPTR createArray(std::vector< unsigned > &dims, gcp::util::DataType::Type dataType, char **data)
Definition: IdlHandler.cc:29
static int idlTypeOf(gcp::util::DataType::Type dataType)
Definition: IdlHandler.cc:97
Definition: IdlHandler.h:35
void addDataMember(std::string name, gcp::util::MonitorDataType &dataType, unsigned len=1)
Definition: IdlHandler.cc:236
IdlHandler(IDL_VPTR vptr)
Definition: IdlHandler.cc:18
Definition: IdlHandler.h:155