00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _EYEDB_ARGUMENT_H
00026 #define _EYEDB_ARGUMENT_H
00027
00028 namespace eyedb {
00029
00035 class ArgArray;
00036 class ArgType;
00037
00041 class Argument : public gbxObject {
00042
00043
00044
00045
00046 public:
00047 enum GarbagePolicy {
00048 NoGarbage = 1,
00049 AutoGarbage,
00050 AutoFullGarbage
00051 };
00052
00053
00054
00055
00056
00057
00061 Argument();
00062
00067 Argument(eyedblib::int16 i);
00068
00073 Argument(eyedblib::int32 i);
00074
00079 Argument(eyedblib::int64 i);
00080
00085 Argument(const char *s);
00086
00091 Argument(char c);
00092
00097 Argument(unsigned char by);
00098
00103 Argument(double d);
00104
00110 Argument(const Oid &oid, Database *db = NULL);
00111
00116 Argument(const Object *o);
00117
00123 Argument(const unsigned char *raw, int size);
00124
00129 Argument(void *x);
00130
00135 Argument(const ArgArray *array);
00136
00137
00143 Argument(char *s, Argument::GarbagePolicy policy);
00144
00150 Argument(Object *o, Argument::GarbagePolicy policy);
00151
00158 Argument(unsigned char *raw, int size, Argument::GarbagePolicy policy);
00159
00165 Argument(ArgArray *array, Argument::GarbagePolicy policy);
00166
00167
00173 Argument(const int *i, int cnt);
00174
00180 Argument(const char *c, int cnt);
00181
00187 Argument(char **s, int cnt);
00188
00194 Argument(const double *d, int cnt);
00195
00202 Argument(const Oid *oid, int cnt, Database *db = 0);
00203
00209 Argument(const Object **o, int cnt);
00210
00211
00218 Argument(int *i, int cnt, Argument::GarbagePolicy policy);
00219
00226 Argument(char *c, int cnt, Argument::GarbagePolicy policy);
00227
00234 Argument(char **s, int cnt, Argument::GarbagePolicy policy);
00235
00242 Argument(double *d, int cnt, Argument::GarbagePolicy policy);
00243
00251 Argument(Oid *oid, int cnt, Argument::GarbagePolicy policy,
00252 Database *db = NULL);
00253
00260 Argument(Object **o, int cnt, Argument::GarbagePolicy policy);
00261
00262
00267 Argument(const Argument & arg);
00268
00269
00275 Argument &operator=(const Argument &arg);
00276
00277
00278
00279
00280
00281
00286 void set(eyedblib::int16 i);
00287
00292 void set(eyedblib::int32 i);
00293
00298 void set(eyedblib::int64 i);
00299
00304 void set(const char *s);
00305
00310 void set(char c);
00311
00316 void set(unsigned char by);
00317
00322 void set(double d);
00323
00329 void set(const Oid &oid, Database *db = 0);
00330
00335 void set(const Object *o);
00336
00342 void set(const unsigned char *raw, int size);
00343
00348 void set(void *x);
00349
00354 void set(const ArgArray *array);
00355
00360 void set(const Argument &arg);
00361
00362
00368 void set(char *s, Argument::GarbagePolicy policy);
00369
00375 void set(Object *o, Argument::GarbagePolicy policy);
00376
00383 void set(unsigned char *raw, int size, Argument::GarbagePolicy policy);
00384
00390 void set(ArgArray *array, Argument::GarbagePolicy policy);
00391
00392
00398 void set(const eyedblib::int16 *i, int cnt);
00399
00405 void set(const eyedblib::int32 *i, int cnt);
00406
00412 void set(const eyedblib::int64 *i, int cnt);
00413
00419 void set(const char *c, int cnt);
00420
00426 void set(char **s, int cnt);
00427
00433 void set(const double *d, int cnt);
00434
00441 void set(const Oid *oid, int cnt, Database *db = 0);
00442
00448 void set(const Object **o, int cnt);
00449
00450
00457 void set(eyedblib::int16 *i, int cnt, Argument::GarbagePolicy policy);
00458
00465 void set(eyedblib::int32 *i, int cnt, Argument::GarbagePolicy policy);
00466
00473 void set(eyedblib::int64 *i, int cnt, Argument::GarbagePolicy policy);
00474
00481 void set(char *c, int cnt, Argument::GarbagePolicy policy);
00482
00489 void set(char **s, int cnt, Argument::GarbagePolicy policy);
00490
00497 void set(double *d, int cnt, Argument::GarbagePolicy policy);
00498
00506 void set(Oid *oid, int cnt, Argument::GarbagePolicy policy,
00507 Database *db = NULL);
00508
00515 void set(Object **o, int cnt, Argument::GarbagePolicy policy);
00516
00517
00518
00519
00520
00521
00526 const eyedblib::int16 *getInteger16() const {
00527 return type->getType() == INT16_TYPE ? &u.i16 : NULL;
00528 }
00529
00534 const eyedblib::int32 *getInteger32() const {
00535 return type->getType() == INT32_TYPE ? &u.i32 : NULL;
00536 }
00537
00542 const eyedblib::int64 *getInteger64() const {
00543 return type->getType() == INT64_TYPE ? &u.i64 : NULL;
00544 }
00545
00550 eyedblib::int64 getInteger() const;
00551
00556 const char *getChar() const {
00557 return type->getType() == CHAR_TYPE ? &u.c : NULL;
00558 }
00559
00564 const unsigned char *getByte() const {
00565 return type->getType() == BYTE_TYPE ? &u.by : NULL;
00566 }
00567
00572 const double *getFloat() const {
00573 return type->getType() == FLOAT_TYPE ? &u.d : NULL;
00574 }
00575
00580 const Oid *getOid() const {
00581 return type->getType() == OID_TYPE ? u.oid : NULL;
00582 }
00583
00588 const char *getString() const {
00589 return type->getType() == STRING_TYPE ? u.s : NULL;
00590 }
00591
00596 const Object *getObject() const;
00597
00603 const unsigned char *getRaw(int &size) const {
00604 if (type->getType() == RAW_TYPE) {
00605 size = u.raw.size;
00606 return u.raw.data;
00607 }
00608 return NULL;
00609 }
00610
00616 const unsigned char *getBytes(int &size) const {
00617 return getRaw(size);
00618 }
00619
00624 const void *getX() const {
00625 return type->getType() == ANY_TYPE ? u.x : NULL;
00626 }
00627
00632 char *getString() {
00633 return type->getType() == STRING_TYPE ? u.s : NULL;
00634 }
00635
00640 Object *getObject();
00641
00646 void *getX() {
00647 return type->getType() == ANY_TYPE ? u.x : NULL;
00648 }
00649
00654 const Argument getArgument() {
00655 return *this;
00656 }
00657
00658
00664 const eyedblib::int16 *getIntegers16(int &cnt) const;
00665
00671 const eyedblib::int32 *getIntegers32(int &cnt) const;
00672
00678 const eyedblib::int64 *getIntegers64(int &cnt) const;
00679
00685 const char *getChars(int &cnt) const;
00686
00692 const double *getFloats(int &cnt) const;
00693
00699 const Oid *getOids(int &cnt) const;
00700
00706 char **getStrings(int &cnt) const;
00707
00713 Object **getObjects(int &cnt) const;
00714
00721 static char *alloc(unsigned int sz, char *x);
00722
00729 static unsigned char *alloc(unsigned int sz, unsigned char *x);
00730
00737 static eyedblib::int16 *alloc(unsigned int sz, eyedblib::int16 *x);
00738
00745 static eyedblib::int32 *alloc(unsigned int sz, eyedblib::int32 *x);
00746
00753 static eyedblib::int64 *alloc(unsigned int sz, eyedblib::int64 *x);
00754
00761 static double *alloc(unsigned int sz, double *x);
00762
00769 static Oid *alloc(unsigned int sz, Oid *x);
00770
00777 static char **alloc(unsigned int sz, char **x);
00778
00785 static Object **alloc(unsigned int sz, Object **x);
00786
00792 static char *dup(const char *s);
00793
00800 static unsigned char *dup(const unsigned char *x, int sz);
00801
00808 static eyedblib::int16 *dup(const eyedblib::int16 *x, int cnt);
00809
00816 static eyedblib::int32 *dup(const eyedblib::int32 *x, int cnt);
00817
00824 static eyedblib::int64 *dup(const eyedblib::int64 *x, int cnt);
00825
00832 static double *dup(const double *x, int cnt);
00833
00840 static Oid *dup(const Oid *x, int cnt);
00841
00848 static char **dup(char **x, int cnt);
00849
00856 static Object **dup(Object **x, int cnt);
00857
00862 static void free(char *x);
00863
00868 static void free(unsigned char *x);
00869
00874 static void free(eyedblib::int16 *x);
00875
00880 static void free(eyedblib::int32 *x);
00881
00886 static void free(eyedblib::int64 *x);
00887
00892 static void free(double *x);
00893
00898 static void free(Oid *x);
00899
00905 static void free(char **x, int cnt);
00906
00911 static void free(Object *x);
00912
00918 static void free(Object **x, int cnt);
00919
00920
00925 const ArgType *getType() const {return type;}
00926
00931 ArgType *getType() {return type;}
00932
00937 const char *toString() const;
00938
00942 ~Argument();
00943
00950 static const char *
00951 getArgTypeStr(const ArgType *argType, Bool printref = True);
00952
00953
00954
00955
00956 private:
00957 char *str;
00958 void garbage();
00959 void init(ArgType_Type);
00960 GarbagePolicy policy;
00961
00962
00963
00964
00965 public:
00966 ArgType *type;
00967 Database *db;
00968
00969 unsigned char *code(unsigned int &) const;
00970
00971 union {
00972 eyedblib::int16 i16;
00973 eyedblib::int32 i32;
00974 eyedblib::int64 i64;
00975 char *s;
00976 char c;
00977 unsigned char by;
00978 double d;
00979 Oid *oid;
00980 Object *o;
00981 void *x;
00982 ArgArray *array;
00983 struct {
00984 int size;
00985 unsigned char *data;
00986 } raw;
00987 struct {
00988 int cnt;
00989 eyedblib::int16 *i;
00990 } arr_i16;
00991 struct {
00992 int cnt;
00993 eyedblib::int32 *i;
00994 } arr_i32;
00995 struct {
00996 int cnt;
00997 eyedblib::int64 *i;
00998 } arr_i64;
00999 struct {
01000 int cnt;
01001 char **s;
01002 } arr_s;
01003 struct {
01004 int cnt;
01005 char *c;
01006 } arr_c;
01007 struct {
01008 int cnt;
01009 double *d;
01010 } arr_d;
01011 struct {
01012 int cnt;
01013 Oid *oid;
01014 } arr_oid;
01015 struct {
01016 int cnt;
01017 Object **o;
01018 } arr_o;
01019 } u;
01020 };
01021
01025 class ArgArray : public gbxObject {
01026
01027
01028
01029
01030 public:
01034 ArgArray();
01035
01041 ArgArray(const Argument **args, int cnt);
01042
01049 ArgArray(Argument **args, int cnt, Argument::GarbagePolicy policy);
01050
01056 ArgArray(int cnt, Argument::GarbagePolicy policy);
01057
01064 void set(Argument **args, int cnt, Argument::GarbagePolicy policy);
01065
01070 Argument **getArgs() {return args;}
01071
01076 int getCount() const {return cnt;}
01077
01082 ArgArray(const ArgArray &arg);
01083
01089 ArgArray &operator=(const ArgArray &arg);
01090
01096 ArgArray(unsigned char *c, unsigned int n);
01097
01103 const Argument *operator[](int n) const {
01104 return ((n >= 0 && n < cnt) ? args[n] : (Argument *)0);
01105 }
01106
01112 Argument *operator[](int n) {
01113 return ((n >= 0 && n < cnt) ? args[n] : (Argument *)0);
01114 }
01115
01120 ArgType_Type getType() const;
01121
01127 unsigned char *code(unsigned int &) const;
01128
01133 const char *toString() const;
01134
01138 ~ArgArray();
01139
01140
01141
01142
01143 private:
01144 Argument::GarbagePolicy policy;
01145 void garbage();
01146 char *str;
01147 int cnt;
01148 Argument **args;
01149 };
01150
01151 class ArgumentPtr : public gbxObjectPtr {
01152
01153 public:
01154 ArgumentPtr(Argument *o = 0) : gbxObjectPtr(o) { }
01155
01156 Argument *getArgument() {return dynamic_cast<Argument *>(o);}
01157 const Argument *getArgument() const {return dynamic_cast<Argument *>(o);}
01158
01159 Argument *operator->() {return dynamic_cast<Argument *>(o);}
01160 const Argument *operator->() const {return dynamic_cast<Argument *>(o);}
01161 };
01162
01163 typedef std::vector<ArgumentPtr> ArgumentPtrVector;
01164
01169 }
01170
01171 #endif