Validator.hh

00001 
00019 #ifndef avro_Validating_hh__
00020 #define avro_Validating_hh__
00021 
00022 #include <boost/noncopyable.hpp>
00023 #include <vector>
00024 #include <stdint.h>
00025 
00026 #include "Types.hh"
00027 #include "Node.hh"
00028 
00029 namespace avro {
00030 
00031 class ValidSchema;
00032 class OutputStreamer;
00033 
00039 
00040 class Validator : private boost::noncopyable
00041 {
00042     typedef uint32_t flag_t;
00043 
00044   public:
00045 
00046     explicit Validator(const ValidSchema &schema);
00047 
00048     void advance();
00049     void advanceWithCount(int64_t val);
00050 
00051     bool typeIsExpected(Type type) const {
00052         return (expectedTypesFlag_ & typeToFlag(type));
00053     }
00054 
00055     Type nextTypeExpected() const {
00056         return nextType_;
00057     }
00058 
00059     int nextSizeExpected() const;
00060 
00061     bool getCurrentRecordName(std::string &name) const;
00062     bool getNextFieldName(std::string &name) const;
00063 
00064   private:
00065 
00066     flag_t typeToFlag(Type type) const {
00067         flag_t flag = (1L << type);
00068         return flag;
00069     }
00070 
00071     void setupOperation(const NodePtr &node);
00072 
00073     void setWaitingForCount();
00074 
00075     void recordAdvance();
00076     void enumAdvance();
00077     void countingAdvance();
00078     void unionAdvance();
00079     void fixedAdvance();
00080 
00081     void setupFlag(Type type);
00082 
00083     const ValidSchema &schema_;
00084 
00085     // since this only keeps a reference to the schema, to ensure its parse
00086     // tree is not deleted, keep a copy of a shared pointer to the root of the
00087     // tree
00088 
00089     const NodePtr parseTree_;
00090 
00091     Type nextType_; 
00092     flag_t expectedTypesFlag_;
00093     bool compoundStarted_;
00094     bool waitingForCount_;
00095     int64_t count_;
00096 
00097     struct CompoundType {
00098         explicit CompoundType(const NodePtr &n) :
00099             node(n), pos(0)
00100         {}
00101         NodePtr node;  
00102         size_t  pos; 
00103     };
00104 
00105     std::vector<CompoundType> compoundStack_;
00106     std::vector<size_t> counters_;
00107 
00108 };
00109 
00110 } // namespace avro
00111 
00112 #endif

Generated on Fri Mar 12 13:20:47 2010 for Avro C++ by  doxygen 1.6.1