COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
coObjID.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 #ifndef _CO_OBJID_H_
9 #define _CO_OBJID_H_
10 
11 // 25.09.98
12 
13 #include <iostream>
14 #include "coTypes.h"
15 #ifdef WIN32
16 #include "unixcompat.h"
17 #endif
18 #include <stdio.h>
19 #include <cstring>
20 #include <string>
21 
22 #ifndef INLINE
23 #define INLINE inline
24 #endif
25 
26 namespace covise
27 {
28 
29 class coDistributedObject;
30 
32 struct coObjID
33 {
35  : portID(0)
36  , modID(0)
37  , seqNo(0)
38  , id(NULL)
39  {
40  }
41  coObjID(const char *name)
42  : portID(0)
43  , modID(0)
44  , seqNo(0)
45  , id(NULL)
46  {
47  if (name)
48  {
49  id = new char[strlen(name) + 1];
50  strcpy(id, name);
51  }
52  }
54  : portID(0)
55  , modID(0)
56  , seqNo(0)
57  , id(NULL)
58  {
59  if (name.length() > 0)
60  {
61  id = new char[name.length() + 1];
62  strcpy(id, name.c_str());
63  }
64  }
66  : portID(src.portID)
67  , modID(src.modID)
68  , seqNo(src.seqNo)
69  , id(NULL)
70  {
71  if (src.id)
72  {
73  id = new char[strlen(src.id) + 1];
74  strcpy(id, src.id);
75  }
76  }
78  {
79  portID = src.portID;
80  modID = src.modID;
81  seqNo = src.seqNo;
82  id = NULL;
83  if (src.id)
84  {
85  id = new char[strlen(src.id) + 1];
86  strcpy(id, src.id);
87  }
88  return *this;
89  }
90  // WARNING: if anything else than integers here: major changes in send/recv
91  // for any changes: change shm/coDoHdr.h
92  int portID;
93  int modID;
94  int seqNo;
95  char *id;
96 
97  int getModID() const
98  {
99  return modID;
100  }
101  int getPortID() const
102  {
103  return portID;
104  ;
105  }
106  int getHash() const
107  {
108  return (((portID & 0x00000007)) // 3 bit Mod-ID
109  | ((modID & 0x00000007) << 3) // 3 bit Port-ID
110  | ((seqNo & 0x00000007) << 6));
111  } // 3 bit sequence
112 
113  int getSeqNo() const
114  {
115  return seqNo;
116  }
117  void setInvalid()
118  {
119  seqNo = portID = modID = -1;
120  }
121  int isValid() const
122  {
123  return (seqNo > 0) && (portID > 0) && (modID > 0);
124  }
125  const char *getString() const
126  {
127  static char name[500];
128  snprintf(name, sizeof(name), "coObjID(m=%d,p=%d,seq%d)", modID, portID, seqNo);
129  name[sizeof(name) - 1] = '\0';
130  return name;
131  }
132 
133  UTILEXPORT static int compare(const coObjID &a, const coObjID &b);
134 };
135 
136 UTILEXPORT std::ostream &operator<<(std::ostream &, const coObjID &);
137 
138 // enough for all hash entries...
139 enum
140 {
142 };
143 
144 UTILEXPORT int compare(const coObjID &a, const coObjID &b);
145 
146 INLINE bool operator<(const coObjID &a, const coObjID &b)
147 {
148  return (coObjID::compare(a, b) < 0);
149 }
150 
151 INLINE bool operator>(const coObjID &a, const coObjID &b)
152 {
153  return (coObjID::compare(a, b) > 0);
154 }
155 
156 INLINE bool operator<=(const coObjID &a, const coObjID &b)
157 {
158  return (coObjID::compare(a, b) <= 0);
159 }
160 
161 INLINE bool operator>=(const coObjID &a, const coObjID &b)
162 {
163  return (coObjID::compare(a, b) >= 0);
164 }
165 
166 INLINE bool operator==(const coObjID &a, const coObjID &b)
167 {
168  return (coObjID::compare(a, b) == 0);
169 }
170 
171 INLINE bool operator!=(const coObjID &a, const coObjID &b)
172 {
173  return (coObjID::compare(a, b) != 0);
174 }
175 
181 {
182 
183 private:
184  // Copy-Constructor: NOT IMPLEMENTED
185  coObjIDMaker(const coObjIDMaker &);
186 
187  // Assignment operator: NOT IMPLEMENTED
189 
190  // Default constructor: NOT IMPLEMENTED
191  coObjIDMaker();
192 
193  // My last ObjID
195 
196  // sequence number increment
197  int d_seqInc;
198 
199 public:
201  coObjIDMaker(int32_t modID, int portID, int seqInc = 1, int firstSeqNo = 1)
202  {
203  d_objID.modID = modID;
204  d_objID.portID = portID;
205  d_objID.seqNo = firstSeqNo;
206  d_seqInc = seqInc;
207  }
208 
211  {
213  return d_objID;
214  }
215 
216  // get a new Sequence Number
218  {
219  return d_objID;
220  }
221 
224 };
225 
230 struct UTILEXPORT coObjInfo // if changing this, change in co{Send,Recv}Buffer, too
231 {
232 
233  static int sequence;
234  static char *baseName;
236  {
237  blockNo = numBlocks = timeStep = numTimeSteps = -1;
238  time = -1.0f;
239  reqModID = 0;
240  }
241  coObjInfo(const char *name)
242  {
243  blockNo = numBlocks = timeStep = numTimeSteps = -1;
244  time = -1.0f;
245  reqModID = 0;
246  if (baseName)
247  {
248  if (strlen(name) == 0)
249  {
250  id = baseName;
251  }
252  else
253  {
254  char *n;
255  if (baseName)
256  {
257  size_t l = strlen(baseName) + strlen(name) + 50;
258  n = new char[l];
259  snprintf(n, l, "%s_%d_%s", name, sequence, baseName);
260  n[l - 1] = '\0';
261  }
262  else
263  {
264  size_t l = strlen(name) + 50;
265  n = new char[l];
266  snprintf(n, l, "%s_%d", name, sequence);
267  n[l - 1] = '\0';
268  }
269  sequence++;
270  id = n;
271  delete[] n;
272  }
273  }
274  else
275  id = name;
276  }
278  {
279  blockNo = numBlocks = timeStep = numTimeSteps = -1;
280  time = -1.0f;
281  reqModID = 0;
282  id = name;
283  }
284  static void setBaseName(const char *bn)
285  {
286  delete[] baseName;
287  sequence = 0;
288  if (bn)
289  {
290  baseName = new char[strlen(bn) + 1];
291  strcpy(baseName, bn);
292  }
293  else
294  baseName = NULL;
295  };
296  enum
297  {
298  UNKNOWN = -2,
299  TIMESTEP_ALL = -1,
300  NUM_TIMESTEPS_INFINIT = -1
301  };
302 
304  int blockNo, numBlocks, timeStep, numTimeSteps;
305  float time;
306  int32_t reqModID; // needed for Object request only: modID of asking module
307 
308  const char *getName() const
309  {
310  return id.id;
311  }
312 };
313 
314 UTILEXPORT std::ostream &operator<<(std::ostream &, const coObjInfo &);
315 
316 INLINE int operator==(const coObjInfo &a, const coObjInfo &b)
317 {
318  return ((coObjID::compare(a.id, b.id) == 0)
319  && (a.blockNo == b.blockNo)
320  && (a.numBlocks == b.numBlocks)
321  && (a.timeStep == b.timeStep)
322  && (a.numTimeSteps == b.numTimeSteps)
323  && (a.time == b.time));
324 }
325 }
326 
327 #endif
coObjInfo()
Definition: coObjID.h:235
int getPortID() const
Definition: coObjID.h:101
int getModID() const
Definition: coObjID.h:97
coObjID(const coObjID &src)
Definition: coObjID.h:65
int timeStep
Definition: coObjID.h:304
const char * getName() const
Definition: coObjID.h:308
GLuint const GLchar * name
Definition: khronos-glext.h:6722
static UTILEXPORT int compare(const coObjID &a, const coObjID &b)
Definition: coObjID.cpp:29
coObjInfo(const char *name)
Definition: coObjID.h:241
Definition: coObjID.h:141
GLdouble n
Definition: khronos-glext.h:8447
GLboolean GLboolean GLboolean b
Definition: khronos-glext.h:6895
GLenum GLuint id
Definition: khronos-glext.h:6279
coObjIDMaker & operator=(const coObjIDMaker &)
coObjID()
Definition: coObjID.h:34
const char * getString() const
Definition: coObjID.h:125
coObjID getNewID()
get a new Sequence Number
Definition: coObjID.h:210
coObjID(const char *name)
Definition: coObjID.h:41
#define NULL
Definition: covise_list.h:22
GLsizei const GLchar *const * string
Definition: khronos-glext.h:6750
coObjID id
Definition: coObjID.h:303
Definition: coObjID.h:230
int blockNo
Definition: coObjID.h:304
INLINE bool operator<=(const coObjID &a, const coObjID &b)
Definition: coObjID.h:156
int getSeqNo() const
Definition: coObjID.h:113
int modID
Definition: coObjID.h:93
#define INLINE
Definition: coObjID.h:23
INLINE bool operator>(const coObjID &a, const coObjID &b)
Definition: coObjID.h:151
static void setBaseName(const char *bn)
Definition: coObjID.h:284
~coObjIDMaker()
Destructor.
Definition: coObjID.h:223
GLboolean GLboolean GLboolean GLboolean a
Definition: khronos-glext.h:6895
coObjInfo(const std::string &name)
Definition: coObjID.h:277
int32_t reqModID
Definition: coObjID.h:306
coObjID & operator=(const coObjID &src)
Definition: coObjID.h:77
INLINE bool operator!=(const coObjID &a, const coObjID &b)
Definition: coObjID.h:171
char * id
Definition: coObjID.h:95
INLINE bool operator==(const coObjID &a, const coObjID &b)
Definition: coObjID.h:166
Definition: coObjID.h:180
int seqNo
Definition: coObjID.h:94
static char * baseName
Definition: coObjID.h:234
int portID
Definition: coObjID.h:92
coObjID d_objID
Definition: coObjID.h:194
UTILEXPORT int compare(const coObjID &a, const coObjID &b)
float time
Definition: coObjID.h:305
int numTimeSteps
Definition: coObjID.h:304
INLINE bool operator>=(const coObjID &a, const coObjID &b)
Definition: coObjID.h:161
int getHash() const
Definition: coObjID.h:106
static int sequence
Definition: coObjID.h:233
const int UNKNOWN
Definition: covise_shm.h:138
coObjIDMaker(int32_t modID, int portID, int seqInc=1, int firstSeqNo=1)
Constructor: set Module-ID, Port-ID, sequence increment and start value.
Definition: coObjID.h:201
GLenum src
Definition: khronos-glext.h:7031
int d_seqInc
Definition: coObjID.h:197
INLINE bool operator<(const coObjID &a, const coObjID &b)
Definition: coObjID.h:146
int numBlocks
Definition: coObjID.h:304
int isValid() const
Definition: coObjID.h:121
#define UTILEXPORT
Definition: coExport.h:182
void setInvalid()
Definition: coObjID.h:117
coObjID getLastID()
Definition: coObjID.h:217
coObjID(const std::string &name)
Definition: coObjID.h:53
QTextStream & operator<<(QTextStream &out, const coConfigEntryStringList list)
Definition: coConfigEntryString.cpp:166
Object-ID structure.
Definition: coObjID.h:32