rtlfield.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef rtlfield_hpp
  14. #define rtlfield_hpp
  15. #include "eclhelper.hpp"
  16. #include "eclrtl.hpp"
  17. /*
  18. The classes in this file are used to represent the type of various fields, and information about the fields.
  19. They are primarily designed to be used in generated code, so should have as little overhead as possible when used
  20. in that context. For that reason the classes have no destructors.
  21. The file rtldynfield contains classes which manage instances of these classes which are dynamically created.
  22. */
  23. // A base implementation of RtlTypeInfo
  24. struct ECLRTL_API RtlTypeInfoBase : public RtlTypeInfo
  25. {
  26. inline RtlTypeInfoBase(unsigned _fieldType, unsigned _length) : RtlTypeInfo(_fieldType, _length) {}
  27. virtual size32_t size(const byte * self, const byte * selfrow) const;
  28. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  29. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  30. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  31. virtual const char * queryLocale() const;
  32. virtual const RtlFieldInfo * const * queryFields() const;
  33. virtual const RtlTypeInfo * queryChildType() const;
  34. };
  35. //-------------------------------------------------------------------------------------------------------------------
  36. struct ECLRTL_API RtlBoolTypeInfo : public RtlTypeInfoBase
  37. {
  38. inline RtlBoolTypeInfo(unsigned _fieldType, unsigned _length) : RtlTypeInfoBase(_fieldType, _length) {}
  39. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  40. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  41. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  42. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  43. virtual __int64 getInt(const void * ptr) const;
  44. };
  45. struct ECLRTL_API RtlRealTypeInfo : public RtlTypeInfoBase
  46. {
  47. inline RtlRealTypeInfo(unsigned _fieldType, unsigned _length) : RtlTypeInfoBase(_fieldType, _length) {}
  48. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  49. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  50. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  51. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  52. virtual __int64 getInt(const void * ptr) const;
  53. private:
  54. inline double value(const void * self) const;
  55. };
  56. //MORE: Create specialist versions
  57. struct ECLRTL_API RtlIntTypeInfo : public RtlTypeInfoBase
  58. {
  59. inline RtlIntTypeInfo(unsigned _fieldType, unsigned _length) : RtlTypeInfoBase(_fieldType, _length) {}
  60. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  61. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  62. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  63. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  64. virtual __int64 getInt(const void * ptr) const;
  65. };
  66. struct ECLRTL_API RtlSwapIntTypeInfo : public RtlTypeInfoBase
  67. {
  68. inline RtlSwapIntTypeInfo(unsigned _fieldType, unsigned _length) : RtlTypeInfoBase(_fieldType, _length) {}
  69. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  70. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  71. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  72. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  73. virtual __int64 getInt(const void * ptr) const;
  74. };
  75. struct ECLRTL_API RtlPackedIntTypeInfo : public RtlTypeInfoBase
  76. {
  77. inline RtlPackedIntTypeInfo(unsigned _fieldType, unsigned _length) : RtlTypeInfoBase(_fieldType, _length) {}
  78. virtual size32_t size(const byte * self, const byte * selfrow) const;
  79. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  80. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  81. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  82. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  83. virtual __int64 getInt(const void * ptr) const;
  84. };
  85. struct ECLRTL_API RtlStringTypeInfo : public RtlTypeInfoBase
  86. {
  87. inline RtlStringTypeInfo(unsigned _fieldType, unsigned _length) : RtlTypeInfoBase(_fieldType, _length) {}
  88. virtual size32_t size(const byte * self, const byte * selfrow) const;
  89. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  90. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  91. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  92. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  93. virtual __int64 getInt(const void * ptr) const;
  94. };
  95. struct ECLRTL_API RtlDataTypeInfo : public RtlTypeInfoBase
  96. {
  97. inline RtlDataTypeInfo(unsigned _fieldType, unsigned _length) : RtlTypeInfoBase(_fieldType, _length) {}
  98. virtual size32_t size(const byte * self, const byte * selfrow) const;
  99. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  100. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  101. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  102. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  103. virtual __int64 getInt(const void * ptr) const;
  104. };
  105. struct ECLRTL_API RtlVarStringTypeInfo : public RtlTypeInfoBase
  106. {
  107. inline RtlVarStringTypeInfo(unsigned _fieldType, unsigned _length) : RtlTypeInfoBase(_fieldType, _length) {}
  108. virtual size32_t size(const byte * self, const byte * selfrow) const;
  109. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  110. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  111. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  112. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  113. virtual __int64 getInt(const void * ptr) const;
  114. };
  115. struct ECLRTL_API RtlQStringTypeInfo : public RtlTypeInfoBase
  116. {
  117. inline RtlQStringTypeInfo(unsigned _fieldType, unsigned _length) : RtlTypeInfoBase(_fieldType, _length) {}
  118. virtual size32_t size(const byte * self, const byte * selfrow) const;
  119. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  120. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  121. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  122. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  123. virtual __int64 getInt(const void * ptr) const;
  124. };
  125. struct ECLRTL_API RtlDecimalTypeInfo : public RtlTypeInfoBase
  126. {
  127. inline RtlDecimalTypeInfo(unsigned _fieldType, unsigned _length) : RtlTypeInfoBase(_fieldType, _length) {}
  128. virtual size32_t size(const byte * self, const byte * selfrow) const;
  129. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  130. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  131. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  132. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  133. virtual __int64 getInt(const void * ptr) const;
  134. size32_t calcSize() const;
  135. };
  136. struct ECLRTL_API RtlCharTypeInfo : public RtlTypeInfoBase
  137. {
  138. inline RtlCharTypeInfo(unsigned _fieldType, unsigned _length) : RtlTypeInfoBase(_fieldType, _length) {}
  139. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  140. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  141. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  142. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  143. virtual __int64 getInt(const void * ptr) const;
  144. };
  145. struct ECLRTL_API RtlUnicodeTypeInfo : public RtlTypeInfoBase
  146. {
  147. public:
  148. inline RtlUnicodeTypeInfo(unsigned _fieldType, unsigned _length, const char * _locale) : RtlTypeInfoBase(_fieldType, _length), locale(_locale) {}
  149. virtual size32_t size(const byte * self, const byte * selfrow) const;
  150. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  151. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  152. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  153. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  154. virtual __int64 getInt(const void * ptr) const;
  155. virtual const char * queryLocale() const { return locale; }
  156. protected:
  157. const char * locale;
  158. };
  159. struct ECLRTL_API RtlVarUnicodeTypeInfo : public RtlTypeInfoBase
  160. {
  161. public:
  162. inline RtlVarUnicodeTypeInfo(unsigned _fieldType, unsigned _length, const char * _locale) : RtlTypeInfoBase(_fieldType, _length), locale(_locale) {}
  163. virtual size32_t size(const byte * self, const byte * selfrow) const;
  164. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  165. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  166. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  167. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  168. virtual __int64 getInt(const void * ptr) const;
  169. virtual const char * queryLocale() const { return locale; }
  170. protected:
  171. const char * locale;
  172. };
  173. struct ECLRTL_API RtlUtf8TypeInfo : public RtlTypeInfoBase
  174. {
  175. public:
  176. inline RtlUtf8TypeInfo(unsigned _fieldType, unsigned _length, const char * _locale) : RtlTypeInfoBase(_fieldType, _length), locale(_locale) {}
  177. virtual size32_t size(const byte * self, const byte * selfrow) const;
  178. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  179. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  180. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  181. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  182. virtual __int64 getInt(const void * ptr) const;
  183. virtual const char * queryLocale() const { return locale; }
  184. protected:
  185. const char * locale;
  186. };
  187. struct ECLRTL_API RtlRecordTypeInfo : public RtlTypeInfoBase
  188. {
  189. inline RtlRecordTypeInfo(unsigned _fieldType, unsigned _length, const RtlFieldInfo * const * _fields) : RtlTypeInfoBase(_fieldType, _length), fields(_fields) {}
  190. const RtlFieldInfo * const * fields; // null terminated
  191. virtual size32_t size(const byte * self, const byte * selfrow) const;
  192. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  193. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  194. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  195. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  196. virtual __int64 getInt(const void * ptr) const;
  197. virtual const RtlFieldInfo * const * queryFields() const { return fields; }
  198. };
  199. struct ECLRTL_API RtlCompoundTypeInfo : public RtlTypeInfoBase
  200. {
  201. inline RtlCompoundTypeInfo(unsigned _fieldType, unsigned _length, const RtlTypeInfo * _child) : RtlTypeInfoBase(_fieldType, _length), child(_child) {}
  202. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  203. virtual __int64 getInt(const void * ptr) const;
  204. virtual const RtlTypeInfo * queryChildType() const { return child; }
  205. const RtlTypeInfo * child;
  206. };
  207. struct ECLRTL_API RtlSetTypeInfo : public RtlCompoundTypeInfo
  208. {
  209. inline RtlSetTypeInfo(unsigned _fieldType, unsigned _length, const RtlTypeInfo * _child) : RtlCompoundTypeInfo(_fieldType, _length, _child) {}
  210. virtual size32_t size(const byte * self, const byte * selfrow) const;
  211. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  212. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  213. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  214. };
  215. struct ECLRTL_API RtlRowTypeInfo : public RtlCompoundTypeInfo
  216. {
  217. inline RtlRowTypeInfo(unsigned _fieldType, unsigned _length, const RtlTypeInfo * _child) : RtlCompoundTypeInfo(_fieldType, _length, _child) {}
  218. virtual size32_t size(const byte * self, const byte * selfrow) const;
  219. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  220. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  221. };
  222. struct ECLRTL_API RtlDatasetTypeInfo : public RtlCompoundTypeInfo
  223. {
  224. inline RtlDatasetTypeInfo(unsigned _fieldType, unsigned _length, const RtlTypeInfo * _child) : RtlCompoundTypeInfo(_fieldType, _length, _child) {}
  225. virtual size32_t size(const byte * self, const byte * selfrow) const;
  226. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  227. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  228. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  229. };
  230. struct ECLRTL_API RtlDictionaryTypeInfo : public RtlCompoundTypeInfo
  231. {
  232. inline RtlDictionaryTypeInfo(unsigned _fieldType, unsigned _length, const RtlTypeInfo * _child, IHThorHashLookupInfo *_hashInfo)
  233. : RtlCompoundTypeInfo(_fieldType, _length, _child), hashInfo(_hashInfo) {}
  234. IHThorHashLookupInfo * hashInfo;
  235. virtual size32_t size(const byte * self, const byte * selfrow) const;
  236. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const;
  237. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  238. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  239. };
  240. struct ECLRTL_API RtlIfBlockTypeInfo : public RtlTypeInfoBase
  241. {
  242. inline RtlIfBlockTypeInfo(unsigned _fieldType, unsigned _length, const RtlFieldInfo * const * _fields) : RtlTypeInfoBase(_fieldType, _length), fields(_fields) {}
  243. const RtlFieldInfo * const * fields; // null terminated
  244. virtual bool getCondition(const byte * selfrow) const = 0;
  245. virtual size32_t size(const byte * self, const byte * selfrow) const;
  246. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  247. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  248. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  249. virtual __int64 getInt(const void * ptr) const;
  250. virtual const RtlFieldInfo * const * queryFields() const { return fields; }
  251. };
  252. struct ECLRTL_API RtlBitfieldTypeInfo : public RtlTypeInfoBase
  253. {
  254. inline RtlBitfieldTypeInfo(unsigned _fieldType, unsigned _length) : RtlTypeInfoBase(_fieldType, _length) {}
  255. virtual size32_t size(const byte * self, const byte * selfrow) const;
  256. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  257. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  258. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  259. virtual __int64 getInt(const void * ptr) const;
  260. protected:
  261. __int64 signedValue(const void * self) const;
  262. unsigned __int64 unsignedValue(const void * self) const;
  263. };
  264. struct ECLRTL_API RtlUnimplementedTypeInfo : public RtlTypeInfoBase
  265. {
  266. inline RtlUnimplementedTypeInfo(unsigned _fieldType, unsigned _length) : RtlTypeInfoBase(_fieldType, _length) {}
  267. virtual size32_t size(const byte * self, const byte * selfrow) const;
  268. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  269. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  270. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const;
  271. virtual __int64 getInt(const void * ptr) const;
  272. };
  273. /*
  274. struct ECLRTL_API RtlAlienTypeInfo : public RtlTypeInfoBase
  275. {
  276. public:
  277. inline RtlAlienTypeInfo(unsigned _fieldType, unsigned _length) : RtlTypeInfoBase(_fieldType, _length) {}
  278. virtual size32_t size(const byte * self, const byte * selfrow) const = 0;
  279. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const;
  280. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & target) const;
  281. };
  282. */
  283. //-------------------------------------------------------------------------------------------------------------------
  284. struct ECLRTL_API RtlFieldStrInfo : public RtlFieldInfo
  285. {
  286. RtlFieldStrInfo(const char * _name, const char * _xpath, const RtlTypeInfo * _type);
  287. RtlFieldStrInfo(const char * _name, const char * _xpath, const RtlTypeInfo * _type, const char * _initializer);
  288. };
  289. #endif