C:/Projets/hexamonkey/core/variable/variable.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 VARIABLE_H
00019 #define VARIABLE_H
00020 
00021 #include <memory>
00022 #include <vector>
00023 
00024 #include "core/variant.h"
00025 
00026 class VariableImplementation;
00027 
00039 class Variable
00040 {
00041 public:
00045     Variable();
00051     Variable(VariableImplementation* implementation, bool modifiable);
00052 
00056     void setValue(const Variant &value);
00057 
00061     Variant value() const;
00062 
00068     Variable field(const Variant& key, bool modifable = false);
00069 
00073     void setField(const Variant& key, const Variable& variable);
00074 
00078     void setConstant();
00079 
00083     bool isDefined() const;
00084 
00088     void inPlaceCopy(bool modifiable = true);
00089 
00093     static Variable copy(const Variant& value, bool modifiable = true);
00094 
00098     static Variable ref(Variant& value, bool modifiable = true);
00099 
00103     static Variable constRef(const Variant& value);
00104 
00108     static Variable nullConstant();
00109 
00110 private:
00111     enum class Tag {undefined = 0, constant = 1, modifiable = 2};
00112 
00113     std::shared_ptr<VariableImplementation> _implementation;
00114     Tag _tag;
00115 };
00116 
00120 class VariableImplementation
00121 {
00122 public:
00123     virtual ~VariableImplementation();
00124 protected:
00125     friend class Variable;
00126 
00127     virtual Variant doGetValue();
00128     virtual void doSetValue(const Variant& value);
00129 
00130     virtual Variable doGetField(const Variant& key, bool modifiable);
00131     virtual void doSetField(const Variant& key, const Variable& variable);
00132 };
00133 
00134 #endif // VARIABLE_H