Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
ScriptLibraryData Class Reference

#include <ored/portfolio/scriptedtrade.hpp>

+ Inheritance diagram for ScriptLibraryData:
+ Collaboration diagram for ScriptLibraryData:

Public Member Functions

 ScriptLibraryData ()
 
 ScriptLibraryData (const ScriptLibraryData &d)
 
 ScriptLibraryData (ScriptLibraryData &&d)
 
ScriptLibraryDataoperator= (const ScriptLibraryData &d)
 
ScriptLibraryDataoperator= (ScriptLibraryData &&d)
 
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (ore::data::XMLDocument &doc) const override
 
bool has (const std::string &scriptName, const std::string &purpose, const bool fallBackOnEmptyPurpose=true) const
 
std::pair< std::string, ScriptedTradeScriptDataget (const std::string &scriptName, const std::string &purpose, const bool fallBackOnEmptyPurpose=true) const
 
- Public Member Functions inherited from XMLSerializable
virtual ~XMLSerializable ()
 
virtual void fromXML (XMLNode *node)=0
 
virtual XMLNodetoXML (XMLDocument &doc) const =0
 
void fromFile (const std::string &filename)
 
void toFile (const std::string &filename) const
 
void fromXMLString (const std::string &xml)
 Parse from XML string. More...
 
std::string toXMLString () const
 Parse from XML string. More...
 

Private Attributes

std::map< std::string, std::pair< std::string, std::map< std::string, ScriptedTradeScriptData > > > scripts_
 

Detailed Description

Definition at line 180 of file scriptedtrade.hpp.

Constructor & Destructor Documentation

◆ ScriptLibraryData() [1/3]

Definition at line 182 of file scriptedtrade.hpp.

182{}

◆ ScriptLibraryData() [2/3]

Definition at line 593 of file scriptedtrade.cpp.

593{ scripts_ = d.scripts_; }
std::map< std::string, std::pair< std::string, std::map< std::string, ScriptedTradeScriptData > > > scripts_

◆ ScriptLibraryData() [3/3]

Definition at line 595 of file scriptedtrade.cpp.

595{ scripts_ = std::move(d.scripts_); }

Member Function Documentation

◆ operator=() [1/2]

ScriptLibraryData & operator= ( const ScriptLibraryData d)

Definition at line 597 of file scriptedtrade.cpp.

597 {
598 scripts_ = d.scripts_;
599 return *this;
600}

◆ operator=() [2/2]

ScriptLibraryData & operator= ( ScriptLibraryData &&  d)

Definition at line 602 of file scriptedtrade.cpp.

602 {
603 scripts_ = std::move(d.scripts_);
604 return *this;
605}

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Implements XMLSerializable.

Definition at line 636 of file scriptedtrade.cpp.

636 {
637 XMLUtils::checkNode(node, "ScriptLibrary");
638 auto childs = XMLUtils::getChildrenNodes(node, "Script");
639 std::set<std::string> loadedNames;
640 for (auto c : childs) {
641 std::string name = XMLUtils::getChildValue(c, "Name");
642 QL_REQUIRE(std::find(loadedNames.begin(), loadedNames.end(), name) == loadedNames.end(),
643 "duplicate script with name '" << name << "'");
644 loadedNames.insert(name);
645 std::string productTag = XMLUtils::getChildValue(c, "ProductTag", false);
646 scripts_[name].first = productTag;
647 auto sn = XMLUtils::getChildrenNodes(c, "Script");
648 QL_REQUIRE(!sn.empty(), "no node Script found for '" << name << "'");
649 for (auto& n : sn) {
650 ScriptedTradeScriptData d;
651 d.fromXML(n);
652 std::string purpose = XMLUtils::getAttribute(n, "purpose");
653 scripts_[name].second[purpose] = d;
654 TLOG("loaded script '" << name << "' (purpose='" << purpose << "', productTag='" << productTag << "')");
655 }
656 }
657}
static string getAttribute(XMLNode *node, const string &attrName)
Definition: xmlutils.cpp:419
static void checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
#define TLOG(text)
Logging Macro (Level = Data)
Definition: log.hpp:556
string name
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( ore::data::XMLDocument doc) const
overridevirtual

Implements XMLSerializable.

Definition at line 659 of file scriptedtrade.cpp.

659 {
660 XMLNode* n = doc.allocNode("ScriptLibrary");
661 for (auto& s : scripts_) {
662 XMLNode* c = XMLUtils::addChild(doc, n, "Script");
663 XMLUtils::addChild(doc, c, "Name", s.first);
664 XMLUtils::addChild(doc, c, "ProductTag", s.second.first);
665 for (auto& t : s.second.second) {
666 XMLNode* n = t.second.toXML(doc);
667 XMLUtils::addAttribute(doc, n, "purpose", t.first);
669 }
670 }
671 return n;
672}
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
static void addAttribute(XMLDocument &doc, XMLNode *node, const string &attrName, const string &attrValue)
Definition: xmlutils.cpp:412
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:

◆ has()

bool has ( const std::string &  scriptName,
const std::string &  purpose,
const bool  fallBackOnEmptyPurpose = true 
) const

Definition at line 607 of file scriptedtrade.cpp.

608 {
609 auto s = scripts_.find(scriptName);
610 if (s != scripts_.end()) {
611 return s->second.second.find(purpose) != s->second.second.end() ||
612 (fallBackOnEmptyPurpose && has(scriptName, "", false));
613 }
614 return false;
615}
bool has(const std::string &scriptName, const std::string &purpose, const bool fallBackOnEmptyPurpose=true) const

◆ get()

std::pair< std::string, ScriptedTradeScriptData > get ( const std::string &  scriptName,
const std::string &  purpose,
const bool  fallBackOnEmptyPurpose = true 
) const

Definition at line 617 of file scriptedtrade.cpp.

619 {
620 auto s = scripts_.find(scriptName);
621 if (s != scripts_.end()) {
622 auto f = s->second.second.find(purpose);
623 if (f != s->second.second.end()) {
624 return std::make_pair(s->second.first, f->second);
625 } else if (fallBackOnEmptyPurpose) {
626 auto f = s->second.second.find("");
627 if (f != s->second.second.end())
628 return std::make_pair(s->second.first, f->second);
629 }
630 }
631 QL_FAIL("ScriptedTradeScriptData::get(): script '" << scriptName << "' with purpose '" << purpose
632 << "' not found, fallBackOnEmptyPurpose was " << std::boolalpha
633 << fallBackOnEmptyPurpose);
634}
+ Here is the caller graph for this function:

Member Data Documentation

◆ scripts_

std::map<std::string, std::pair<std::string, std::map<std::string, ScriptedTradeScriptData> > > scripts_
private

Definition at line 199 of file scriptedtrade.hpp.