Parser.hh

00001 
00019 #ifndef avro_Parser_hh__
00020 #define avro_Parser_hh__
00021 
00022 #include "Reader.hh"
00023 
00024 namespace avro {
00025 
00030 
00031 template<class Reader>
00032 class Parser : private boost::noncopyable
00033 {
00034 
00035   public:
00036 
00037     // Constructor only works with Writer
00038     explicit Parser(const InputBuffer &in) :
00039         reader_(in)
00040     {}
00041 
00043     Parser(const ValidSchema &schema, const InputBuffer &in) :
00044         reader_(schema, in)
00045     {}
00046 
00047     void readNull() {
00048         Null null;
00049         reader_.readValue(null);
00050     }
00051 
00052     bool readBool() {
00053         bool val;
00054         reader_.readValue(val);
00055         return val;
00056     }
00057 
00058     int32_t readInt() {
00059         int32_t val;
00060         reader_.readValue(val);
00061         return val;
00062     }
00063 
00064     int64_t readLong() {
00065         int64_t val;
00066         reader_.readValue(val);
00067         return val;
00068     }
00069 
00070     float readFloat() {
00071         float val;
00072         reader_.readValue(val);
00073         return val;
00074     }
00075 
00076     double readDouble() {
00077         double val;
00078         reader_.readValue(val);
00079         return val;
00080     }
00081 
00082     void readString(std::string &val) {
00083         reader_.readValue(val);
00084     }
00085 
00086     void readBytes(std::vector<uint8_t> &val) {
00087         reader_.readBytes(val);
00088     }
00089 
00090     template <size_t N>
00091     void readFixed(uint8_t (&val)[N]) {
00092         reader_.readFixed(val);
00093     }
00094 
00095     template<size_t N>
00096     void readFixed(boost::array<uint8_t, N> &val) {
00097         reader_.readFixed(val);
00098     }
00099 
00100     void readRecord() { 
00101         reader_.readRecord();
00102     }
00103 
00104     void readRecordEnd() { 
00105         reader_.readRecordEnd();
00106     }
00107 
00108     int64_t readArrayBlockSize() {
00109         return reader_.readArrayBlockSize();
00110     }
00111 
00112     int64_t readUnion() { 
00113         return reader_.readUnion();
00114     }
00115 
00116     int64_t readEnum() {
00117         return reader_.readEnum();
00118     }
00119 
00120     int64_t readMapBlockSize() {
00121         return reader_.readMapBlockSize();
00122     }
00123 
00124   private:
00125 
00126     friend Type nextType(Parser<ValidatingReader> &p);
00127     friend bool currentRecordName(Parser<ValidatingReader> &p, std::string &name);
00128     friend bool nextFieldName(Parser<ValidatingReader> &p, std::string &name);
00129 
00130     Reader reader_;
00131 
00132 };
00133 
00134 inline Type nextType(Parser<ValidatingReader> &p) {
00135     return p.reader_.nextType();
00136 }
00137 
00138 inline bool currentRecordName(Parser<ValidatingReader> &p, std::string &name) {
00139     return p.reader_.currentRecordName(name);
00140 }
00141 
00142 inline bool nextFieldName(Parser<ValidatingReader> &p, std::string &name) {
00143     return p.reader_.nextFieldName(name);
00144 }
00145 
00146 } // namespace avro
00147 
00148 #endif
Generated on Thu Sep 2 18:40:54 2010 for Avro C++ by  doxygen 1.6.3