C:/Projets/hexamonkey/core/interpreter/program.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 EBMLOBJECT_H
00019 #define EBMLOBJECT_H
00020 
00021 #include <memory>
00022 #include <set>
00023 
00024 #include "core/object.h"
00025 #include "core/module.h"
00026 #include "core/variable/variablepath.h"
00027 
00036 class Program
00037 {
00038     class Memory
00039     {
00040         friend class ProgramLoader;
00041         friend class Program;
00042 
00043         File& file();
00044         Object& setFileObject(Object* fileObject);
00045 
00046         RealFile _file;
00047         std::unique_ptr<Object> _fileObject;
00048     };
00049 
00050     template<class It>
00051     class _const_iterator : public std::iterator<std::input_iterator_tag, Program>
00052     {
00053         friend class Program;
00054         It _it;
00055         std::shared_ptr<Memory> _memory;
00056 
00057         _const_iterator<It>(const It& it, std::shared_ptr<Memory> memory):_it(it), _memory(memory){}
00058         public:
00059             _const_iterator<It>(){}
00060             _const_iterator<It>& operator++() {++_it; return *this;}
00061             _const_iterator<It> operator++(int) {const_iterator dup(*this); ++_it; return dup;}
00062             _const_iterator<It>& operator--() {--_it; return *this;}
00063             _const_iterator<It> operator--(int) {const_iterator dup(*this); --_it; return dup;}
00064             Program operator*() const {return Program(**_it, _memory);}
00065             bool operator==(const _const_iterator<It>& other) const {return _it==other._it;}
00066             bool operator!=(const _const_iterator<It>& other) const {return !(*this==other);}
00067     };
00068 
00069 public:
00070     typedef _const_iterator< Object::iterator > const_iterator;
00071     typedef _const_iterator< Object::reverse_iterator > const_reverse_iterator;
00072 
00073     Program();
00074 
00078     bool isValid() const;
00084     uint32_t tag() const;
00085 
00091     const Variant& payload() const;
00092 
00096     int size() const;
00097 
00103     Program node(int index) const;
00104 
00110     Program operator[](int index) const;
00111 
00115     const_iterator begin() const;
00116 
00120     const_iterator end() const;
00121 
00125     const_reverse_iterator rbegin() const;
00126 
00130     const_reverse_iterator rend() const;
00131 
00132 private:
00133     friend class ProgramLoader;
00134 
00135     Program(Object& object, std::shared_ptr<Memory> memory);
00136 
00137     Program::Memory& memory() const;
00138 
00139     Object* _object;
00140     std::shared_ptr<Program::Memory> _memory;
00141 };
00142 
00143 #endif // EBMLOBJECT_H