CompilerNode.hh

00001 
00019 #ifndef avro_CompilerNode_hh__
00020 #define avro_CompilerNode_hh__
00021 
00022 #include "NodeConcepts.hh"
00023 #include "Node.hh"
00024 
00025 namespace avro {
00026 
00027 
00035 
00036 class CompilerNode
00037 {
00038 
00039   public:
00040 
00041     enum AttributeType {
00042         NONE,
00043         FIELDS,
00044         VALUES,
00045         ITEMS,
00046         TYPES
00047     };
00048 
00049     CompilerNode() :
00050         type_(AVRO_NUM_TYPES),
00051         attributeType_(NONE)
00052     {}
00053 
00054     CompilerNode(const CompilerNode &rhs) :
00055         type_(rhs.type_),
00056         attributeType_(rhs.attributeType_)
00057     {}
00058 
00059 
00060     AttributeType attributeType() const {
00061         return attributeType_;
00062     }
00063 
00064     void setAttributeType(AttributeType attributeType) {
00065         attributeType_ = attributeType;
00066     }
00067 
00068     Type type() const {
00069         return type_;
00070     }
00071 
00072     void setType(Type type) {
00073         type_ = type;
00074     } 
00075 
00076     void addNode(const NodePtr &node) {
00077         switch(attributeType_) {
00078           case FIELDS:
00079             fieldsAttribute_.add(node);
00080             break;
00081           case VALUES:
00082             valuesAttribute_.add(node);
00083             break;
00084           case ITEMS:
00085             itemsAttribute_.add(node);
00086             break;
00087           case TYPES:
00088             typesAttribute_.add(node);
00089             break;
00090 
00091           default:
00092             throw Exception("Can't add node if the attribute type is not set");
00093         }
00094     }
00095 
00096 
00097     // attribute used by records, enums, symbols, and fixed:
00098     concepts::SingleAttribute<std::string> nameAttribute_;
00099 
00100     // attribute used by fixed:
00101     concepts::SingleAttribute<int> sizeAttribute_;
00102 
00103     // attributes used by records:
00104     concepts::MultiAttribute<NodePtr>     fieldsAttribute_;
00105     concepts::MultiAttribute<std::string> fieldsNamesAttribute_;
00106 
00107     // attribute used by enums:
00108     concepts::MultiAttribute<std::string> symbolsAttribute_;
00109 
00110     // attribute used by arrays:
00111     concepts::SingleAttribute<NodePtr> itemsAttribute_;
00112 
00113     // attribute used by maps:
00114     concepts::SingleAttribute<NodePtr> valuesAttribute_;
00115 
00116     // attribute used by unions:
00117     concepts::MultiAttribute<NodePtr> typesAttribute_;
00118 
00119     Type type_;
00120     AttributeType attributeType_;
00121 
00122 };
00123 
00124 NodePtr nodeFromCompilerNode(CompilerNode &compilerNode);
00125 
00126 } // namespace avro
00127 
00128 #endif
Generated on Thu Sep 2 18:40:54 2010 for Avro C++ by  doxygen 1.6.3