C:/Projets/hexamonkey/core/parser.h
Go to the documentation of this file.
00001 //This file is part of the HexaMonkey project, a multimedia analyser
00002 //Copyright (C) 2013  Sevan Drapeau-Martin, Nicolas Fleury
00003 
00004 //This program is free software; you can redistribute it and/or
00005 //modify it under the terms of the GNU General Public License
00006 //as published by the Free Software Foundation; either version 2
00007 //of the License, or (at your option) any later version.
00008 
00009 //This program is distributed in the hope that it will be useful,
00010 //but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //GNU General Public License for more details.
00013 
00014 //You should have received a copy of the GNU General Public License
00015 //along with this program; if not, write to the Free Software
00016 //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017 
00018 #ifndef PARSER_H
00019 #define PARSER_H
00020 
00021 #include <string>
00022 
00023 #include "core/object.h"
00024 
00040 class Parser
00041 {
00042 public:
00043     virtual ~Parser(){}
00044 
00048     virtual void parseHead();
00049 
00053     virtual void parse();
00054 
00058     virtual bool parseSome(int hint);
00059 
00063     virtual void parseTail();
00064 
00068     bool headParsed() const;
00069 
00073     bool parsed() const;
00074 
00078     bool tailParsed() const;
00079 
00083     Object &object();
00084     const Object &object() const;
00085 
00086 protected:
00087     Parser(Object& object);
00088 
00092     ObjectType *modifiableType();
00093     const ObjectType& constType() const;
00094 
00099     int64_t availableSize() const;
00100 
00104     void setHeadParsed();
00105 
00109     void setParsed();
00110 
00114     void setNoHead();
00115 
00119     void setNoTail();
00120 
00121 
00125     virtual void doParseHead();
00126 
00130     virtual void doParse();
00131 
00139     virtual bool doParseSome(int hint);
00140 
00146     virtual void doParseTail();
00147 
00148 
00149 private:
00150     friend class SimpleParser;
00151     friend class ContainerParser;
00152     friend class BlockExecution;
00153     friend class ParserTypeScope;
00154 
00155     Object& _object;
00156     std::unique_ptr<ObjectType> _type;
00157 
00158     bool lockObject();
00159     void unlockObject();
00160 
00161     bool _headParsed;
00162     bool _parsed;
00163     bool _tailParsed;
00164     bool _hasHead;
00165     bool _hasTail;
00166 };
00167 
00174 class SimpleParser : public Parser
00175 {
00176 public:
00177     virtual ~SimpleParser() {}
00178 
00179     void parseHead() override;
00180 
00181 protected:
00182     SimpleParser(Object& object);
00183 
00184 private:
00185     void doParse() override;
00186     bool doParseSome(int hint) override;
00187 };
00188 
00189 #endif // PARSER_H