Pol  Revision:cb584c9
xmlfilescrobj.h
Go to the documentation of this file.
1 
7 #ifndef XMLSCROBJ_H
8 #define XMLSCROBJ_H
9 
10 #ifndef BSCRIPT_BOBJECT_H
11 #include "../bscript/bobject.h"
12 #endif
13 
14 #include <string>
15 #include <tinyxml/tinyxml.h>
16 
17 #include "../bscript/contiter.h"
18 #include "../clib/compilerspecifics.h"
19 #include "../clib/rawtypes.h"
20 
21 namespace Pol {
22 namespace Bscript {
23 class Executor;
24 } // namespace Bscript
25 } // namespace Pol
26 
27 namespace Pol
28 {
29 namespace Core
30 {
32 {
33 public:
34  BXMLNodeIterator( TiXmlDocument* file, Bscript::BObject* pIter );
35  BXMLNodeIterator( TiXmlNode* node, Bscript::BObject* pIter );
36  virtual Bscript::BObject* step() POL_OVERRIDE;
37 
38 private:
39  TiXmlNode* node;
40  TiXmlDocument* _file;
41  bool _init;
44 };
45 
47 {
48 public:
49  BXMLAttributeIterator( TiXmlElement* node, Bscript::BObject* pIter );
50  virtual Bscript::BObject* step() POL_OVERRIDE;
51 
52 private:
53  TiXmlElement* node;
54  TiXmlAttribute* nodeAttrib;
57 };
58 
60 {
61 public:
62  BXMLfile();
63  BXMLfile( std::string filename );
64  ~BXMLfile();
65  virtual Bscript::BObjectRef get_member( const char* membername ) POL_OVERRIDE;
66  virtual Bscript::BObjectRef get_member_id( const int id ) POL_OVERRIDE; // id test
67  virtual Bscript::BObjectImp* call_method( const char* methodname,
69  virtual Bscript::BObjectImp* call_method_id( const int id, Bscript::Executor& ex,
70  bool forcebuiltin = false ) POL_OVERRIDE;
71  virtual Bscript::BObjectImp* copy() const POL_OVERRIDE;
72  virtual std::string getStringRep() const POL_OVERRIDE;
73  virtual size_t sizeEstimate() const POL_OVERRIDE
74  {
75  return sizeof( *this ) + _filename.capacity();
76  }
77  virtual const char* typeOf() const POL_OVERRIDE { return "XMLFile"; }
78  virtual u8 typeOfInt() const POL_OVERRIDE { return OTXMLFile; }
79  virtual bool isTrue() const POL_OVERRIDE;
80  virtual Bscript::BObjectRef OperSubscript( const Bscript::BObject& obj ) POL_OVERRIDE;
81  virtual Bscript::ContIterator* createIterator( Bscript::BObject* pIterVal ) POL_OVERRIDE
82  {
83  return new BXMLNodeIterator( &file, pIterVal );
84  }
85 
86 private:
87  TiXmlDocument file;
88  std::string _filename;
89 };
90 
91 
93 {
94 public:
95  BXmlNode( TiXmlNode* _node )
96  : Bscript::BObjectImp( Bscript::BObjectImp::OTXMLNode ), node( _node )
97  {
98  }
99 
100  virtual Bscript::BObjectImp* copy() const POL_OVERRIDE { return new BXmlNode( node->Clone() ); }
101  virtual std::string getStringRep() const POL_OVERRIDE;
102 
103  virtual const char* typeOf() const POL_OVERRIDE { return "XMLNode"; }
104  virtual u8 typeOfInt() const POL_OVERRIDE { return OTXMLNode; }
105  virtual size_t sizeEstimate() const POL_OVERRIDE { return sizeof( *this ) + sizeof( TiXmlNode ); }
106  virtual Bscript::ContIterator* createIterator( Bscript::BObject* pIterVal ) POL_OVERRIDE
107  {
108  return new BXMLNodeIterator( node, pIterVal );
109  }
110 
111  virtual Bscript::BObjectRef get_member( const char* membername ) POL_OVERRIDE;
112  virtual Bscript::BObjectRef get_member_id( const int id ) POL_OVERRIDE; // id test
113  virtual Bscript::BObjectImp* call_method( const char* methodname,
115  virtual Bscript::BObjectImp* call_method_id( const int id, Bscript::Executor& ex,
116  bool forcebuiltin = false ) POL_OVERRIDE;
117  virtual Bscript::BObjectRef OperSubscript( const Bscript::BObject& obj ) POL_OVERRIDE;
118  TiXmlNode* getNode() const { return node; }
119 private:
120  TiXmlNode* node;
121 };
122 
124 {
125 public:
126  BXmlAttribute( TiXmlNode* _node )
127  : Bscript::BObjectImp( Bscript::BObjectImp::OTXMLAttributes ), node( _node->ToElement() )
128  {
129  }
130 
132  {
133  return new BXmlAttribute( node->Clone() );
134  }
135 
136  virtual std::string getStringRep() const POL_OVERRIDE { return "XMLAttributes"; }
137  virtual const char* typeOf() const POL_OVERRIDE { return "XMLAttributes"; }
138  virtual u8 typeOfInt() const POL_OVERRIDE { return OTXMLAttributes; }
139  virtual size_t sizeEstimate() const POL_OVERRIDE { return sizeof( *this ); }
141  {
142  return new BXMLAttributeIterator( node, pIterVal );
143  }
144  virtual Bscript::BObjectImp* call_method( const char* methodname,
146  virtual Bscript::BObjectImp* call_method_id( const int id, Bscript::Executor& ex,
147  bool forcebuiltin = false ) POL_OVERRIDE;
148  virtual Bscript::BObjectRef OperSubscript( const Bscript::BObject& obj ) POL_OVERRIDE;
149 
150 private:
151  TiXmlElement* node;
152 };
153 }
154 }
155 
156 #endif
Bscript::BObjectRef m_IterVal
Definition: xmlfilescrobj.h:42
unsigned char u8
Definition: rawtypes.h:25
virtual Bscript::ContIterator * createIterator(Bscript::BObject *pIterVal) POL_OVERRIDE
BXmlNode(TiXmlNode *_node)
Definition: xmlfilescrobj.h:95
#define POL_OVERRIDE
Bscript::BLong * m_pIterVal
Definition: xmlfilescrobj.h:43
virtual Bscript::BObjectImp * copy() const POL_OVERRIDE
virtual size_t sizeEstimate() const POL_OVERRIDE
Definition: xmlfilescrobj.h:73
virtual u8 typeOfInt() const POL_OVERRIDE
virtual const char * typeOf() const POL_OVERRIDE
virtual size_t sizeEstimate() const POL_OVERRIDE
virtual u8 typeOfInt() const POL_OVERRIDE
virtual u8 typeOfInt() const POL_OVERRIDE
Definition: xmlfilescrobj.h:78
virtual const char * typeOf() const POL_OVERRIDE
Bscript::BObjectRef m_IterVal
Definition: xmlfilescrobj.h:55
virtual Bscript::ContIterator * createIterator(Bscript::BObject *pIterVal) POL_OVERRIDE
TiXmlDocument file
Definition: xmlfilescrobj.h:87
virtual size_t sizeEstimate() const POL_OVERRIDE
virtual Bscript::BObjectImp * copy() const POL_OVERRIDE
virtual std::string getStringRep() const POL_OVERRIDE
virtual Bscript::ContIterator * createIterator(Bscript::BObject *pIterVal) POL_OVERRIDE
Definition: xmlfilescrobj.h:81
TiXmlNode * getNode() const
std::string _filename
Definition: xmlfilescrobj.h:88
Definition: berror.cpp:12
BXmlAttribute(TiXmlNode *_node)
virtual const char * typeOf() const POL_OVERRIDE
Definition: xmlfilescrobj.h:77