deffield.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 _DEFFIELD_HPP
  14. #define _DEFFIELD_HPP
  15. #include "jptree.hpp"
  16. #include "deftype.hpp"
  17. #include "defvalue.hpp"
  18. enum DefElemKind { DEKnone, DEKrecord, DEKifblock, DEKfield, DEKattr };
  19. interface IDefRecordElement : public IInterface
  20. {
  21. virtual DefElemKind getKind() const = 0;
  22. virtual size32_t getMaxSize() const = 0;
  23. virtual unsigned numChildren() const = 0;
  24. virtual ITypeInfo *queryType() const = 0;
  25. virtual IAtom * queryName() const = 0;
  26. virtual IDefRecordElement * queryChild(unsigned i) const = 0;
  27. virtual IValue * queryCompareValue() const = 0;
  28. virtual bool operator==(IDefRecordElement const & other) const = 0;
  29. };
  30. typedef IArrayOf<IDefRecordElement> IDefRecordElementArray;
  31. //fields of type record/dataset have queryChild(0) as the dataset
  32. //ifblocks have queryChild(0) as the condition field, queryChild(1) as the child record
  33. //unnamed records (used for inheritance) are already expanded inline
  34. //records are not commoned up - even if the same structure is used with two names. This ensures each field has a unique IDefRecordElement
  35. //Whether a field needs biasing is determined by the numKeyedFields() and the number of root fields
  36. interface IDefRecordMeta : public IInterface
  37. {
  38. virtual IDefRecordElement * queryRecord() const = 0;
  39. virtual unsigned numKeyedFields() const = 0;
  40. virtual bool equals(const IDefRecordMeta *other) const = 0;
  41. virtual bool IsShared() const = 0;
  42. };
  43. //Interfaces used by compiler to generate the meta information.
  44. interface IDefRecordBuilder : public IInterface
  45. {
  46. virtual void addChild(IDefRecordElement * element) = 0;
  47. virtual void addChildOwn(IDefRecordElement * element) = 0;
  48. virtual IDefRecordElement * close() = 0;
  49. };
  50. extern DEFTYPE_API IDefRecordElement * createDEfield(IAtom * name, ITypeInfo * type, IDefRecordElement * record, size32_t maxSize=0);
  51. extern DEFTYPE_API IDefRecordBuilder * createDErecord(size32_t maxSize);
  52. extern DEFTYPE_API IDefRecordElement * createDEifblock(IDefRecordElement * field, IValue * value, IDefRecordElement * record);
  53. extern DEFTYPE_API IDefRecordMeta * createDefRecordMeta(IDefRecordElement * record, unsigned numKeyed);
  54. extern DEFTYPE_API void serializeRecordMeta(MemoryBuffer & target, IDefRecordMeta * meta, bool compress);
  55. extern DEFTYPE_API IDefRecordMeta * deserializeRecordMeta(MemoryBuffer & source, bool compress);
  56. extern DEFTYPE_API void serializeRecordMeta(IPropertyTree * target, IDefRecordMeta * meta);
  57. extern DEFTYPE_API IDefRecordMeta * deserializeRecordMeta(const IPropertyTree * source);
  58. extern DEFTYPE_API StringBuffer & getRecordMetaAsString(StringBuffer & out, IDefRecordMeta const * meta);
  59. #endif