[120] | 1 | /** |
---|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
---|
| 3 | * or more contributor license agreements. See the NOTICE file |
---|
| 4 | * distributed with this work for additional information |
---|
| 5 | * regarding copyright ownership. The ASF licenses this file |
---|
| 6 | * to you under the Apache License, Version 2.0 (the |
---|
| 7 | * "License"); you may not use this file except in compliance |
---|
| 8 | * with the License. You may obtain a copy of the License at |
---|
| 9 | * |
---|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 11 | * |
---|
| 12 | * Unless required by applicable law or agreed to in writing, software |
---|
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 15 | * See the License for the specific language governing permissions and |
---|
| 16 | * limitations under the License. |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #ifndef TYPEIDS_HH_ |
---|
| 20 | #define TYPEIDS_HH_ |
---|
| 21 | |
---|
| 22 | #include "recordio.hh" |
---|
| 23 | #include "fieldTypeInfo.hh" |
---|
| 24 | |
---|
| 25 | namespace hadoop { |
---|
| 26 | |
---|
| 27 | class FieldTypeInfo; |
---|
| 28 | |
---|
| 29 | /* |
---|
| 30 | * enum of types. We define assign values to individual bytes, rather |
---|
| 31 | * than use enums because we want to make teh values consistent with |
---|
| 32 | * Java code, so we need to control the values. |
---|
| 33 | */ |
---|
| 34 | const int8_t RIOTYPE_BOOL = 1; |
---|
| 35 | const int8_t RIOTYPE_BUFFER = 2; |
---|
| 36 | const int8_t RIOTYPE_BYTE = 3; |
---|
| 37 | const int8_t RIOTYPE_DOUBLE = 4; |
---|
| 38 | const int8_t RIOTYPE_FLOAT = 5; |
---|
| 39 | const int8_t RIOTYPE_INT = 6; |
---|
| 40 | const int8_t RIOTYPE_LONG = 7; |
---|
| 41 | const int8_t RIOTYPE_MAP = 8; |
---|
| 42 | const int8_t RIOTYPE_STRING = 9; |
---|
| 43 | const int8_t RIOTYPE_STRUCT = 10; |
---|
| 44 | const int8_t RIOTYPE_VECTOR = 11; |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | /* |
---|
| 49 | * Represents typeID for basic types. |
---|
| 50 | * Serializes just the single int8_t. |
---|
| 51 | */ |
---|
| 52 | class TypeID { |
---|
| 53 | |
---|
| 54 | public: |
---|
| 55 | |
---|
| 56 | TypeID(int8_t typeVal) {this->typeVal = typeVal;} |
---|
| 57 | TypeID(const TypeID& t) {this->typeVal = t.typeVal;} |
---|
| 58 | virtual ~TypeID() {} |
---|
| 59 | |
---|
| 60 | int8_t getTypeVal() const {return typeVal;} |
---|
| 61 | virtual void serialize(::hadoop::OArchive& a_, const char* tag) const; |
---|
| 62 | |
---|
| 63 | virtual bool operator==(const TypeID& peer_) const; |
---|
| 64 | virtual TypeID* clone() const {return new TypeID(*this);} |
---|
| 65 | |
---|
| 66 | virtual void print(int space=0) const; |
---|
| 67 | |
---|
| 68 | protected: |
---|
| 69 | int8_t typeVal; |
---|
| 70 | }; |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | /* |
---|
| 74 | * no predefined TypeID objects, since memory management becomes difficult. |
---|
| 75 | * If some TypeID objects are consts and others are new-ed, becomes hard to |
---|
| 76 | * destroy const objects without reference counting. |
---|
| 77 | */ |
---|
| 78 | /*const TypeID TID_BoolTypeID(RIOTYPE_BOOL); |
---|
| 79 | const TypeID TID_BufferTypeID(RIOTYPE_BUFFER); |
---|
| 80 | const TypeID TID_ByteTypeID(RIOTYPE_BYTE); |
---|
| 81 | const TypeID TID_DoubleTypeID(RIOTYPE_DOUBLE); |
---|
| 82 | const TypeID TID_FloatTypeID(RIOTYPE_FLOAT); |
---|
| 83 | const TypeID TID_IntTypeID(RIOTYPE_INT); |
---|
| 84 | const TypeID TID_LongTypeID(RIOTYPE_LONG); |
---|
| 85 | const TypeID TID_StringTypeID(RIOTYPE_STRING);*/ |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | /* |
---|
| 89 | * TypeID for structures |
---|
| 90 | */ |
---|
| 91 | class StructTypeID : public TypeID { |
---|
| 92 | |
---|
| 93 | private: |
---|
| 94 | // note: we own the memory mgmt of TypeInfo objects stored in the vector |
---|
| 95 | std::vector<FieldTypeInfo*> typeInfos; |
---|
| 96 | FieldTypeInfo* genericReadTypeInfo(::hadoop::IArchive& a_, const char* tag); |
---|
| 97 | TypeID* genericReadTypeID(::hadoop::IArchive& a_, const char* tag); |
---|
| 98 | |
---|
| 99 | public: |
---|
| 100 | /*StructTypeID(const char* p); |
---|
| 101 | StructTypeID(std::string* p); |
---|
| 102 | StructTypeID(const StructTypeID& ti);*/ |
---|
| 103 | StructTypeID(): TypeID(RIOTYPE_STRUCT) {}; |
---|
| 104 | StructTypeID(const std::vector<FieldTypeInfo*>& vec); |
---|
| 105 | virtual ~StructTypeID(); |
---|
| 106 | |
---|
| 107 | void add(FieldTypeInfo *pti); |
---|
| 108 | std::vector<FieldTypeInfo*>& getFieldTypeInfos() {return typeInfos;} |
---|
| 109 | StructTypeID* findStruct(const char *pStructName); |
---|
| 110 | void serialize(::hadoop::OArchive& a_, const char* tag) const; |
---|
| 111 | void serializeRest(::hadoop::OArchive& a_, const char* tag) const; |
---|
| 112 | void deserialize(::hadoop::IArchive& a_, const char* tag); |
---|
| 113 | virtual TypeID* clone() const {return new StructTypeID(*this);} |
---|
| 114 | |
---|
| 115 | virtual void print(int space=0) const; |
---|
| 116 | |
---|
| 117 | }; |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | /* |
---|
| 121 | * TypeID for vectors |
---|
| 122 | */ |
---|
| 123 | class VectorTypeID : public TypeID { |
---|
| 124 | |
---|
| 125 | private: |
---|
| 126 | // ptiElement's memory mgmt is owned by class |
---|
| 127 | TypeID* ptiElement; |
---|
| 128 | |
---|
| 129 | public: |
---|
| 130 | VectorTypeID(TypeID* ptiElement): TypeID(RIOTYPE_VECTOR), ptiElement(ptiElement) {} |
---|
| 131 | VectorTypeID(const VectorTypeID& ti); |
---|
| 132 | virtual ~VectorTypeID(); |
---|
| 133 | |
---|
| 134 | const TypeID* getElementTypeID() {return ptiElement;} |
---|
| 135 | virtual TypeID* clone() const {return new VectorTypeID(*this);} |
---|
| 136 | void serialize(::hadoop::OArchive& a_, const char* tag) const; |
---|
| 137 | virtual bool operator==(const TypeID& peer_) const; |
---|
| 138 | |
---|
| 139 | virtual void print(int space=0) const; |
---|
| 140 | }; |
---|
| 141 | |
---|
| 142 | /* |
---|
| 143 | * TypeID for maps |
---|
| 144 | */ |
---|
| 145 | class MapTypeID : public TypeID { |
---|
| 146 | |
---|
| 147 | private: |
---|
| 148 | // ptiKay and ptiValue's memory mgmt is owned by class |
---|
| 149 | TypeID* ptiKey; |
---|
| 150 | TypeID* ptiValue; |
---|
| 151 | |
---|
| 152 | public: |
---|
| 153 | MapTypeID(TypeID* ptiKey, TypeID* ptiValue): |
---|
| 154 | TypeID(RIOTYPE_MAP), ptiKey(ptiKey), ptiValue(ptiValue) {} |
---|
| 155 | MapTypeID(const MapTypeID& ti); |
---|
| 156 | virtual ~MapTypeID(); |
---|
| 157 | |
---|
| 158 | const TypeID* getKeyTypeID() {return ptiKey;} |
---|
| 159 | const TypeID* getValueTypeID() {return ptiValue;} |
---|
| 160 | virtual TypeID* clone() const {return new MapTypeID(*this);} |
---|
| 161 | void serialize(::hadoop::OArchive& a_, const char* tag) const; |
---|
| 162 | virtual bool operator==(const TypeID& peer_) const; |
---|
| 163 | |
---|
| 164 | virtual void print(int space=0) const; |
---|
| 165 | }; |
---|
| 166 | |
---|
| 167 | } |
---|
| 168 | #endif // TYPEIDS_HH_ |
---|
| 169 | |
---|