AndroMeta  2.0.0
AndroMeta/include/AndroMeta/MNode.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2009-2012 AndroMeta LLC. All rights reserved.
00003  *
00004  * AndroMeta LLC retains all intellectual property and proprietary 
00005  * rights to this software and related documentation and any modifications 
00006  * thereto.  Any use, reproduction, disclosure, or distribution of this 
00007  * software and related documentation without an express license agreement 
00008  * from AndroMeta LLC is strictly prohibited.
00009  * 
00010  */
00011 
00012 
00020 #ifndef ANDROMETA_M_NODE_H
00021 #define ANDROMETA_M_NODE_H
00022 
00023 #include <iostream>
00024 #include <stdint.h>
00025 
00026 #include <AndroMeta/MStr.h>
00027 #include <AndroMeta/MVector.h>
00028 #include <AndroMeta/MList.h>
00029 
00030 namespace Meta{
00031   
00032   class MVar;
00033   class MObjectBase;
00034   class MObject;
00035   class MNum;
00036   class MReal;
00037   
00048   class MNode{
00049   public:
00050     typedef uint16_t Type;
00051     
00052     static const Type NumericMask =        0x0010;
00053     static const Type DefinedNumericMask = 0x0020;
00054     
00055     static const Type Undefined =          0x0010;
00056     static const Type Constant =           0x0031;
00057     static const Type Integer =            0x0032;
00058     static const Type Rational =           0x0033;
00059     static const Type Float =              0x0034;
00060     static const Type Real =               0x0036;
00061     
00062     static const Type StringMask =         0x0040;
00063     
00064     static const Type String =             0x0040;
00065     static const Type Symbol =             0x0041;
00066     static const Type Function =           0x0042;
00067     
00068     static const Type ObjectMask =         0x0080;
00069     static const Type ObjectPointer =      0x0081;
00070     static const Type LocalObject =        0x0082;
00071     static const Type SharedObject =       0x0083;
00072     
00073     static const Type RawPointer =         0x0100;
00074     
00075     static const Type CodeDataMask =       0x0200;
00076     
00080     MNode();
00081     
00085     MNode(const MNode& n);
00086     
00087     MNode(const MVar& v);
00088     
00089     MNode(MObjectBase* obj, Type t=ObjectPointer);
00090     
00091     MNode(const MObjectBase& obj);
00092     
00093     MNode(Type type, const mstr& value);
00094     
00095     MNode(const MVar* v);
00096     
00097     MNode(MVar* v);
00098     
00099     MNode(MStr* s);
00100     
00101     MNode(const MStr& s);
00102     
00103     MNode(const char* s);
00104     
00105     MNode(bool x);
00106     
00107     MNode(uint8_t x);
00108     
00109     MNode(int8_t x);
00110     
00111     MNode(uint16_t x);
00112     
00113     MNode(int16_t x);
00114     
00115     MNode(uint32_t x);
00116     
00117     MNode(int32_t x);
00118     
00119     MNode(uint64_t x);
00120     
00121     MNode(int64_t x);
00122     
00123 #if defined (__i386__) || defined (__APPLE__)      
00124     
00125     MNode(long int x);
00126     
00127     MNode(unsigned long int x);
00128     
00129 #endif
00130     
00131     MNode(double x);
00132     
00133     MNode(float x);
00134     
00135     MNode(const MVector<MVar>& v);
00136     
00137     MNode(const MList<MVar>& l);
00138     
00139     MNode(const MNum& x);
00140     
00141     MNode(const MReal& x);
00142     
00143     ~MNode();
00144     
00145     static MNode convertVar(const MVar& v, bool convertCodeData=false);
00146     
00147     MVar& attrs();
00148     
00149     const MVar& attrs() const;
00150     
00151     bool hasAttrs() const;
00152     
00153     void clearAttrs(bool recursive=false);
00154     
00155     bool operator==(const MNode& n) const;
00156     
00157     bool operator!=(const MNode& n) const;
00158     
00159     bool isSame(const MNode& n) const;
00160     
00161     MNode& operator=(const MNode& n);
00162     
00163     MNode& operator[](size_t i) const;
00164     
00165     MNode& operator[](int i) const{
00166       return operator[](size_t(i));
00167     }
00168     
00169     MNode& operator[](const MVar& v) const;
00170     
00174     MNode copy() const;
00175     
00183     mstr toStr(bool concise=true, bool quote=true) const;
00184     
00188     MNode& operator+(const MNode& n);
00189     
00190     MVar& var();
00191     
00192     const MVar& var() const;
00193     
00198     MVar& val();
00199     
00200     const MVar& val() const;
00201     
00202     operator bool() const;
00203     
00204     operator double() const;
00205     
00206     operator float() const;
00207     
00208     operator uint8_t() const;
00209     
00210     operator int8_t() const;
00211     
00212     operator uint16_t() const;
00213     
00214     operator int16_t() const;
00215     
00216     operator uint32_t() const;
00217     
00218     operator int32_t() const;
00219     
00220     operator uint64_t() const;
00221     
00222     operator int64_t() const;
00223     
00224     operator const MNum&() const;
00225     
00226 #if defined (__i386__) || defined (__APPLE__)     
00227     
00228     operator unsigned long int() const;
00229     
00230     operator long int() const;
00231     
00232 #endif
00233     
00234     operator const char*() const;
00235     
00236     operator mstr&();
00237     
00238     operator const mstr&() const;
00239     
00240     operator MVar&();
00241     
00242     operator const MVar&() const;
00243     
00244     operator const MVector<MVar>&() const;
00245     
00246     operator MVector<MVar>&();
00247     
00248     operator const MList<MVar>&() const;
00249     
00250     operator MList<MVar>&();
00251     
00255     void add(MNode node);
00256     
00261     void addFront(MNode node);
00262     
00266     void insert(size_t pos, MNode node);
00267     
00271     void remove(size_t pos);
00272     
00277     void append(MNode node);
00278     
00282     size_t size() const;
00283     
00287     bool empty() const;
00288     
00292     void pushBack(MNode node);
00293     
00297     void pushFront(MNode node);
00298     
00302     void push(MNode node);
00303     
00307     MNode popBack();
00308     
00312     MNode popFront();
00313     
00317     MNode pop();
00318     
00322     bool isFunction() const;
00323     
00327     bool isFunction(const mstr& f) const;
00328     
00332     bool isFunction(const mstr& f, size_t args) const;
00333     
00338     bool isFunction(const mstr& f, size_t argsMin, size_t argsMax) const;
00339     
00343     bool isNumeric() const;
00344     
00348     int isRational() const;
00349     
00353     bool isReal() const;
00354     
00358     bool isObject() const;
00359     
00363     bool isSymbol() const;
00364     
00368     bool isSymbol(const mstr& name) const;
00369     
00373     bool isString() const;
00374     
00378     bool isConstant() const;
00379     
00383     bool isCodeData() const;
00384     
00388     bool isSymbolic() const;
00389     
00394     bool isTrue() const;
00395     
00400     bool isFalse() const;
00401     
00405     bool isPtr() const;
00406     
00410     void set(MNode n);
00411     
00415     void clear();
00416     
00420     Type type() const;
00421     
00425     void setLineNumber(size_t lineNumber);
00426     
00430     size_t lineNumber() const;
00431     
00435     void setFileName(const mstr& fileName);
00436     
00440     const mstr& fileName() const;
00441     
00445     void setStartLine(size_t lineNumber);
00446     
00450     size_t startLine() const;
00451 
00455     void setTokenId(int tokenId);
00456     
00461     int tokenId() const;
00462 
00466     void clearInputs();
00467     
00471     void copyParseInfo(MNode node, bool recursive=true);
00472     
00476     MVar toVar() const;
00477     
00481     MObjectBase* obj();
00482     
00486     const mstr& str() const;
00487     
00491     mstr& str();
00492     
00496     const char* cstr() const{
00497       return str().c_str();
00498     }
00499     
00505     void findReplace(MNode f, MNode r);
00506     
00511     void replace(const MVector<MVar>& ns, MNode r);
00512     
00516     void replace(size_t i, MNode ri);
00517     
00521     void replace(MNode r);
00522 
00523   private:
00524     class MNode_* x_;
00525   };
00526   
00527   typedef MNode mnode;
00528   
00532   const mnode mnull;
00533   
00537   mnode mfunc(const mstr& functionName, size_t n);
00538   
00542   inline mnode mfunc(const mstr& functionName){
00543     return MNode(MNode::Function, functionName);
00544   }
00545   
00549   inline mnode msym(const mstr& symbolName){
00550     return MNode(MNode::Symbol, symbolName);
00551   }
00552 
00553   std::ostream& operator<<(std::ostream& ostr, const MNode& n);
00554   
00555 } // end namespace Meta
00556 
00557 #endif // ANDROMETA_M_NODE_H