1/*************** Xobject H Declares Source Code File (.H) **************/
2/* Name: XOBJECT.H Version 2.4 */
3/* */
4/* (C) Copyright to the author Olivier BERTRAND 1998-2014 */
5/* */
6/* This file contains the XOBJECT and derived classes declares. */
7/***********************************************************************/
8
9#ifndef __XOBJECT__H
10#define __XOBJECT__H
11
12/***********************************************************************/
13/* Include required application header files */
14/* block.h is header containing Block global declarations. */
15/***********************************************************************/
16#include "block.h"
17#include "valblk.h" // includes value.h
18
19/***********************************************************************/
20/* Types used in some class definitions. */
21/***********************************************************************/
22typedef class STRING *PSTRG;
23
24/***********************************************************************/
25/* The pointer to the one and only needed void object. */
26/***********************************************************************/
27extern PXOB const pXVOID;
28
29/***********************************************************************/
30/* Class XOBJECT is the base class for all classes that can be used */
31/* in evaluation operations: FILTER, EXPRESSION, SCALF, FNC, COLBLK, */
32/* SELECT, FILTER as well as all the constant object types. */
33/***********************************************************************/
34class DllExport XOBJECT : public BLOCK {
35 public:
36 XOBJECT(void) {Value = NULL; Constant = false;}
37
38 // Implementation
39 PVAL GetValue(void) {return Value;}
40 bool IsConstant(void) {return Constant;}
41 virtual int GetType(void) {return TYPE_XOBJECT;}
42 virtual int GetResultType(void) {return TYPE_VOID;}
43 virtual int GetKey(void) {return 0;}
44#if defined(_DEBUG)
45 virtual void SetKey(int) {assert(false);}
46#else // !_DEBUG
47 virtual void SetKey(int) {} // Only defined for COLBLK
48#endif // !_DEBUG
49 virtual int GetLength(void) = 0;
50 virtual int GetLengthEx(void) = 0;
51 virtual PSZ GetCharValue(void);
52 virtual short GetShortValue(void);
53 virtual int GetIntValue(void);
54 virtual double GetFloatValue(void);
55 virtual int GetScale(void) = 0;
56
57 // Methods
58 virtual void Reset(void) {}
59 virtual bool Compare(PXOB) = 0;
60 virtual bool Init(PGLOBAL) {return false;}
61 virtual bool Eval(PGLOBAL) {return false;}
62 virtual bool SetFormat(PGLOBAL, FORMAT&) = 0;
63
64 protected:
65 PVAL Value; // The current value of the object.
66 bool Constant; // true for an object having a constant value.
67 }; // end of class XOBJECT
68
69/***********************************************************************/
70/* Class XVOID: represent a void (null) object. */
71/* Used to represent a void parameter for count(*) or for a filter. */
72/***********************************************************************/
73class DllExport XVOID : public XOBJECT {
74 public:
75 XVOID(void) {Constant = true;}
76
77 // Implementation
78 virtual int GetType(void) {return TYPE_VOID;}
79 virtual int GetLength(void) {return 0;}
80 virtual int GetLengthEx(void) {return 0;}
81 virtual PSZ GetCharValue(void) {return NULL;}
82 virtual int GetIntValue(void) {return 0;}
83 virtual double GetFloatValue(void) {return 0.0;}
84 virtual int GetScale() {return 0;}
85
86 // Methods
87 virtual bool Compare(PXOB xp) {return xp->GetType() == TYPE_VOID;}
88 virtual bool SetFormat(PGLOBAL, FORMAT&) {return true;}
89 }; // end of class XVOID
90
91
92/***********************************************************************/
93/* Class CONSTANT: represents a constant XOBJECT of any value type. */
94/* Note that the CONSTANT class is a friend of the VALUE class; */
95/***********************************************************************/
96class DllExport CONSTANT : public XOBJECT {
97 public:
98 CONSTANT(PGLOBAL g, void *value, short type);
99 CONSTANT(PGLOBAL g, int n);
100 CONSTANT(PVAL valp) {Value = valp; Constant = true;}
101
102 // Implementation
103 virtual int GetType(void) {return TYPE_CONST;}
104 virtual int GetResultType(void) {return Value->Type;}
105 virtual int GetLength(void) {return Value->GetValLen();}
106 virtual int GetScale() {return Value->GetValPrec();}
107 virtual int GetLengthEx(void);
108
109 // Methods
110 virtual bool Compare(PXOB xp);
111 virtual bool SetFormat(PGLOBAL g, FORMAT& fmt)
112 {return Value->SetConstFormat(g, fmt);}
113 void Convert(PGLOBAL g, int newtype);
114 void SetValue(PVAL vp) {Value = vp;}
115 virtual void Printf(PGLOBAL g, FILE *, uint);
116 virtual void Prints(PGLOBAL g, char *, uint);
117 }; // end of class CONSTANT
118
119/***********************************************************************/
120/* Class STRING handles variable length char strings. */
121/* It is mainly used to avoid buffer overrun. */
122/***********************************************************************/
123class DllExport STRING : public BLOCK {
124 public:
125 // Constructor
126 STRING(PGLOBAL g, uint n, PCSZ str = NULL);
127
128 // Implementation
129 inline int GetLength(void) {return (int)Length;}
130 inline void SetLength(uint n) {Length = n;}
131 inline PSZ GetStr(void) {return Strp;}
132 inline uint32 GetSize(void) {return Size;}
133 inline bool IsTruncated(void) {return Trc;}
134
135 // Methods
136 inline void Reset(void) {*Strp = 0;}
137 bool Set(PCSZ s);
138 bool Set(char *s, uint n);
139 bool Append(const char *s, uint ln, bool nq = false);
140 bool Append(PCSZ s);
141 bool Append(STRING &str);
142 bool Append(char c);
143 bool Resize(uint n);
144 bool Append_quoted(PCSZ s);
145 inline void Trim(void) {(void)Resize(Length + 1);}
146 inline void Chop(void) {if (Length) Strp[--Length] = 0;}
147 inline void RepLast(char c) {if (Length) Strp[Length-1] = c;}
148 inline void Truncate(uint n) {if (n < Length) {Strp[n] = 0; Length = n;}}
149
150 protected:
151 char *Realloc(uint len);
152 inline char *GetNext(void)
153 {return ((char*)G->Sarea)+((PPOOLHEADER)G->Sarea)->To_Free;}
154
155 // Members
156 PGLOBAL G; // To avoid parameter
157 PSZ Strp; // The char string
158 uint Length; // String length
159 uint Size; // Allocated size
160 bool Trc; // When truncated
161 char *Next; // Next alloc position
162 }; // end of class STRING
163
164#endif
165