ARB
aisc_global.h
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : aisc_global.h //
4 // Purpose : //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in May 2007 //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // =============================================================== //
11 #ifndef AISC_GLOBAL_H
12 #define AISC_GLOBAL_H
13 
14 #ifndef BYTESTRING_H
15 #include <bytestring.h>
16 #endif
17 #ifndef ARBTOOLS_H
18 #include <arbtools.h>
19 #endif
20 #ifndef ATTRIBUTES_H
21 #include <attributes.h>
22 #endif
23 #ifndef ARB_ASSERT_H
24 #include <arb_assert.h>
25 #endif
26 
27 #define aisc_assert(cond) arb_assert(cond)
28 
29 // type mask
30 #define AISC_TYPE_NONE 0x00000000
31 #define AISC_TYPE_INT 0x01000000
32 #define AISC_TYPE_DOUBLE 0x02000000
33 #define AISC_TYPE_STRING 0x03000000
34 #define AISC_TYPE_COMMON 0x04000000
35 #define AISC_TYPE_BYTES 0x05000000
36 
37 #define AISC_VAR_TYPE_MASK 0xff000000
38 #define AISC_OBJ_TYPE_MASK 0x00ff0000
39 #define AISC_ATTR_MASK 0x0000ffff
40 
41 #define AISC_INDEX 0x1ff0000
42 #define AISC_NO_ANSWER -0x7fffffff
43 
44 #define AISC_COMMON 0
45 
46 // sync with ../../INCLUDE/arbtools.h@CASTSIG
47 #define AISC_CASTSIG(sig,cb) ((sig)((void*)(cb)))
48 
49 union double_xfer { // workaround aliasing problems
50  double as_double;
51  int as_int[2];
52 };
53 
54 class AISC_Object : public Noncopyable {
55  int type_id;
56  long remote_ptr; // this is a pointer to client-data in server-address-space (casted to long)
57 
58  void *operator&() { return NULp; } // forbid error-prone idiom (AISC_Object just was 'long' in the past). Instead use as_result_param()
59 
60 protected:
61 
62  void set(int IF_ASSERTION_USED(remoteType), long remotePtr) { aisc_assert(remoteType == type_id); remote_ptr = remotePtr; }
63 
64 public:
65  AISC_Object(int type_) : type_id(type_), remote_ptr(0) {}
66 
67  bool exists() const { return remote_ptr; }
68  long get() const { return remote_ptr; }
69  int type() const { return type_id; }
70 
71  void clear() { remote_ptr = 0; }
72  void init(long remotePtr) { aisc_assert(!exists()); set(type_id, remotePtr); }
73 
74  long *as_result_param() { return &remote_ptr; }
75 
76 };
77 
78 #else
79 #error aisc_global.h included twice
80 #endif // AISC_GLOBAL_H
81 
void init(long remotePtr)
Definition: aisc_global.h:72
bool exists() const
Definition: aisc_global.h:67
int type() const
Definition: aisc_global.h:69
AISC_Object(int type_)
Definition: aisc_global.h:65
int as_int[2]
Definition: aisc_global.h:51
void clear()
Definition: aisc_global.h:71
double as_double
Definition: aisc_global.h:50
#define IF_ASSERTION_USED(x)
Definition: arb_assert.h:308
#define aisc_assert(cond)
Definition: aisc_global.h:27
void set(int remoteType, long remotePtr)
Definition: aisc_global.h:62
#define NULp
Definition: cxxforward.h:97
long * as_result_param()
Definition: aisc_global.h:74