11 #include "../bscript/berror.h" 12 #include "../bscript/bobject.h" 13 #include "../bscript/bstruct.h" 14 #include "../bscript/executor.h" 15 #include "../bscript/impstr.h" 16 #include "../bscript/objmembers.h" 17 #include "../bscript/objmethods.h" 18 #include "../clib/stlutil.h" 19 #include "../plib/pkg.h" 26 using namespace Bscript;
32 if ( !
file.LoadFile() )
50 if ( objmember !=
nullptr )
59 if ( objmethod !=
nullptr )
72 return new BError(
"Not enough parameters" );
79 TiXmlDeclaration* decl =
80 new TiXmlDeclaration( version->
value(), encoding->
value(), standalone->
value() );
81 if ( !
file.NoChildren() )
83 if (
file.FirstChild()->Type() == TiXmlNode::TINYXML_DECLARATION )
84 file.RemoveChild(
file.FirstChild() );
85 if ( !
file.NoChildren() )
86 file.InsertBeforeChild(
file.FirstChild(), *decl );
88 file.LinkEndChild( decl );
91 file.LinkEndChild( decl );
92 return new BLong( 1 );
99 return new BError(
"Not enough parameters" );
103 std::unique_ptr<TiXmlElement> elem(
new TiXmlElement( pstr->
value() ) );
110 for ( BStruct::Contents::const_iterator citr = attr->
contents().begin(),
112 citr != end; ++citr )
114 const std::string&
name = ( *citr ).first;
117 elem->SetAttribute( name, static_cast<BLong*>( ref )->value() );
119 elem->SetDoubleAttribute( name, static_cast<Double*>( ref )->value() );
126 file.LinkEndChild( elem.release() );
127 return new BLong( 1 );
134 return new BError(
"Not enough parameters" );
138 TiXmlComment* comment =
new TiXmlComment( pstr->
value().c_str() );
139 file.LinkEndChild( comment );
140 return new BLong( 1 );
147 return new BError(
"Not enough parameters" );
152 TiXmlNode* child =
file.FirstChild( pstr->
value() );
154 return new BLong(
file.RemoveChild( child ) ? 1 : 0 );
156 return new BError(
"Failed to find node" );
161 if ( keyint->
value() != 1 )
162 return new BError(
"Failed to find node" );
163 return new BLong(
file.RemoveChild(
file.RootElement() ) ? 1 : 0 );
168 TiXmlNode* node =
file.ToElement();
169 if ( node != pstr->
getNode()->Parent() )
170 return new BError(
"Failed to find node" );
178 return new BError(
"Not enough parameters" );
185 return new BError(
"Error in filename descriptor" );
187 if ( path.find(
".." ) != std::string::npos )
188 return new BError(
"No parent path traversal please." );
191 return new BError(
"Access denied" );
193 std::string filepath;
194 if ( outpkg ==
nullptr )
197 filepath = outpkg->
dir() + path;
199 return new BLong(
file.SaveFile( filepath ) ? 1 : 0 );
205 std::string indent =
"\t";
210 indent = pstr->
value();
212 TiXmlPrinter printer;
213 printer.SetIndent( indent.c_str() );
215 file.Accept( &printer );
216 return new String( printer.CStr() );
222 return new BError(
"Invalid parameter type" );
235 os <<
file.ErrorRow() <<
"," <<
file.ErrorCol() <<
":" <<
file.ErrorDesc();
243 return !
file.Error();
251 TiXmlNode* node =
file.FirstChild( keystr->
value() );
260 TiXmlHandle handle( &
file );
261 TiXmlNode* node = handle.Child( keyint.
value() - 1 )
270 return BObjectRef(
new BError(
"xml members can only be accessed by name or index" ) );
279 if ( node->ToElement() )
285 switch ( node->Type() )
287 case ( TiXmlNode::TINYXML_COMMENT ):
289 case ( TiXmlNode::TINYXML_DECLARATION ):
291 case ( TiXmlNode::TINYXML_DOCUMENT ):
293 case ( TiXmlNode::TINYXML_ELEMENT ):
295 case ( TiXmlNode::TINYXML_TEXT ):
297 case ( TiXmlNode::TINYXML_TYPECOUNT ):
299 case ( TiXmlNode::TINYXML_UNKNOWN ):
312 if ( objmember !=
nullptr )
321 if ( objmethod !=
nullptr )
338 TiXmlNode* child = node->FirstChild( pstr->
value() );
342 return new BError(
"Failed to find node" );
344 return new BError(
"Invalid parameter type" );
348 TiXmlNode* child = node->FirstChild();
352 return new BError(
"Failed to find node" );
363 TiXmlNode* sibling = node->NextSibling( pstr->
value() );
367 return new BError(
"Failed to find node" );
372 TiXmlNode* sibling = node->NextSibling();
376 return new BError(
"Failed to find node" );
383 return new BError(
"Not enough parameters" );
387 std::unique_ptr<TiXmlElement> elem(
new TiXmlElement( pstr->
value() ) );
394 for ( BStruct::Contents::const_iterator citr = attr->
contents().begin(),
396 citr != end; ++citr )
398 const std::string&
name = ( *citr ).first;
401 elem->SetAttribute( name, static_cast<BLong*>( ref )->value() );
403 elem->SetDoubleAttribute( name, static_cast<Double*>( ref )->value() );
410 TiXmlElement* nodeelem = node->ToElement();
411 nodeelem->LinkEndChild( elem.release() );
412 return new BLong( 1 );
419 return new BError(
"Not enough parameters" );
423 TiXmlComment* comment =
new TiXmlComment( pstr->
value().c_str() );
424 node->LinkEndChild( comment );
425 return new BLong( 1 );
432 return new BError(
"Not enough parameters" );
436 TiXmlElement* elem = node->ToElement();
437 for ( BStruct::Contents::const_iterator citr = attr->
contents().begin(),
439 citr != end; ++citr )
441 const std::string&
name = ( *citr ).first;
444 elem->SetAttribute( name, static_cast<BLong*>( ref )->value() );
446 elem->SetDoubleAttribute( name, static_cast<Double*>( ref )->value() );
450 return new BLong( 1 );
457 return new BError(
"Not enough parameters" );
461 TiXmlElement* elem = node->ToElement();
462 elem->RemoveAttribute( pstr->
value() );
463 return new BLong( 1 );
470 return new BError(
"Not enough parameters" );
475 TiXmlNode* child = node->FirstChild( pstr->
value() );
477 return new BLong( node->RemoveChild( child ) ? 1 : 0 );
479 return new BError(
"Failed to find node" );
484 TiXmlHandle handle( node );
485 TiXmlNode* child = handle.Child( keyint->
value() - 1 )
488 return new BLong( node->RemoveChild( child ) ? 1 : 0 );
490 return new BError(
"Failed to find node" );
495 if ( node->Parent() != pstr->
getNode()->Parent() )
496 return new BError(
"Failed to find node" );
497 return new BLong( node->RemoveChild( pstr->
getNode() ) ? 1 : 0 );
504 return new BError(
"Not enough parameters" );
508 TiXmlElement* elem = node->ToElement();
509 elem->LinkEndChild(
new TiXmlText( pstr->
value() ) );
510 return new BLong( 1 );
521 return new BError(
"Invalid parameter type" );
529 TiXmlNode* child = node->FirstChild( keystr->
value() );
538 TiXmlHandle handle( node );
539 TiXmlNode* child = handle.Child( keyint.
value() - 1 )
548 return BObjectRef(
new BError(
"xml members can only be accessed by name or index" ) );
554 if ( node->Type() == TiXmlNode::TINYXML_TEXT )
555 return node->ToText()->Value();
556 else if ( node->Type() == TiXmlNode::TINYXML_DECLARATION )
558 TiXmlDeclaration* dec = node->ToDeclaration();
560 os <<
"v:" << dec->Version() <<
" e:" << dec->Encoding() <<
" s:" << dec->Standalone();
563 return node->Value();
569 if ( objmethod !=
nullptr )
584 std::unique_ptr<ObjArray> arr(
new ObjArray );
585 TiXmlAttribute* attrib = node->FirstAttribute();
588 arr->addElement(
new String( attrib->Name() ) );
589 attrib = attrib->Next();
591 return arr.release();
603 const std::string* attrib = node->Attribute( keystr->
value() );
611 return BObjectRef(
new BError(
"xml attribute can only be accessed by name" ) );
621 m_pIterVal( new
BLong( 0 ) )
639 if (
node ==
nullptr )
641 else if (
_file ==
nullptr )
676 std::unique_ptr<BStruct> details(
new BStruct() );
678 return new BObject( details.release() );
Bscript::BObjectRef m_IterVal
virtual Bscript::BObjectRef OperSubscript(const Bscript::BObject &obj) POL_OVERRIDE
bool HasWriteAccess(const Plib::Package *pkg, const Plib::Package *filepackage, const std::string &path)
virtual Bscript::BObjectImp * call_method(const char *methodname, Bscript::Executor &ex) POL_OVERRIDE
virtual std::string getStringRep() const POL_OVERRIDE
Bscript::BLong * m_pIterVal
virtual std::string getStringRep() const =0
const EScriptProgram * prog() const
const std::string & value() const
virtual Bscript::BObjectImp * call_method_id(const int id, Bscript::Executor &ex, bool forcebuiltin=false) POL_OVERRIDE
virtual Bscript::BObject * step() POL_OVERRIDE
bool isa(BObjectType type) const
virtual Bscript::BObjectImp * call_method(const char *methodname, Bscript::Executor &ex) POL_OVERRIDE
ObjMember * getKnownObjMember(const char *token)
virtual Bscript::BObjectRef get_member_id(const int id) POL_OVERRIDE
virtual Bscript::BObjectImp * call_method(const char *methodname, Bscript::Executor &ex) POL_OVERRIDE
const Contents & contents() const
#define OSTRINGSTREAM_STR(x)
virtual Bscript::BObjectRef OperSubscript(const Bscript::BObject &obj) POL_OVERRIDE
ObjMethod * getKnownObjMethod(const char *token)
virtual Bscript::BObjectImp * call_method_id(const int id, Bscript::Executor &ex, bool forcebuiltin=false) POL_OVERRIDE
BXMLAttributeIterator(TiXmlElement *node, Bscript::BObject *pIter)
bool pkgdef_split(const std::string &spec, const Package *inpkg, const Package **outpkg, std::string *path)
Bscript::BObjectRef m_IterVal
static UninitObject * create()
virtual Bscript::BObjectRef get_member(const char *membername) POL_OVERRIDE
virtual Bscript::BObject * step() POL_OVERRIDE
virtual Bscript::BObjectImp * copy() const POL_OVERRIDE
virtual bool isTrue() const POL_OVERRIDE
virtual Bscript::BObjectRef OperSubscript(const Bscript::BObject &obj) POL_OVERRIDE
Plib::Package const * pkg
virtual Bscript::BObjectImp * call_method_id(const int id, Bscript::Executor &ex, bool forcebuiltin=false) POL_OVERRIDE
virtual std::string getStringRep() const POL_OVERRIDE
const String * getStringParam(unsigned param)
Bscript::BLong * m_pIterVal
D explicit_cast(const S &s)
bool hasParams(unsigned howmany) const
TiXmlNode * getNode() const
BXMLNodeIterator(TiXmlDocument *file, Bscript::BObject *pIter)
virtual Bscript::BObjectRef get_member_id(const int id) POL_OVERRIDE
TiXmlAttribute * nodeAttrib
BObjectImp * getParamImp(unsigned param)
const std::string & dir() const
virtual Bscript::BObjectRef get_member(const char *membername) POL_OVERRIDE