Parser.hh

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

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