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

Serializable object holding generic trade data, reporting dimensions. More...

#include <ored/portfolio/envelope.hpp>

+ Inheritance diagram for Envelope:
+ Collaboration diagram for Envelope:

Public Member Functions

 Envelope ()
 Default constructor. More...
 
 Envelope (const string &counterparty, const string &nettingSetId, const set< string > &portfolioIds=set< string >())
 Constructor with netting set id and portfolio ids, without additional fields. More...
 
 Envelope (const string &counterparty, const NettingSetDetails &nettingSetDetails=NettingSetDetails(), const set< string > &portfolioIds=set< string >())
 Constructor with netting set details and portfolio ids, without additional fields. More...
 
 Envelope (const string &counterparty, const map< string, string > &additionalFields)
 Constructor without netting set / portfolio ids, with additional fields. More...
 
 Envelope (const string &counterparty, const string &nettingSetId, const map< string, string > &additionalFields, const set< string > &portfolioIds=set< string >())
 Constructor with netting set, with additional fields. More...
 
 Envelope (const string &counterparty, const NettingSetDetails &nettingSetDetails, const map< string, string > &additionalFields, const set< string > &portfolioIds=set< string >())
 Constructor with netting set details, with additional fields. More...
 
Serialisation
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 
Inspectors
const string & counterparty () const
 
const string & nettingSetId () const
 
const NettingSetDetails nettingSetDetails () const
 
const set< string > & portfolioIds () const
 
const map< string, string > additionalFields () const
 
const map< string, boost::any > & fullAdditionalFields () const
 
string additionalField (const std::string &name, const bool mandatory=true, const std::string &defaultValue=std::string()) const
 
boost::any additionalAnyField (const std::string &name, const bool mandatory=true, const boost::any &defaultValue=boost::none) const
 
void setAdditionalField (const std::string &key, const boost::any &value)
 
- 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...
 

Utility

string counterparty_
 
NettingSetDetails nettingSetDetails_
 
set< string > portfolioIds_
 
map< string, boost::any > additionalFields_
 
bool initialized_ = false
 
bool initialized () const
 Check if the envelope is initialized. More...
 
bool hasNettingSetDetails () const
 Check if the netting set details have been populated. More...
 

Detailed Description

Serializable object holding generic trade data, reporting dimensions.

Definition at line 51 of file envelope.hpp.

Constructor & Destructor Documentation

◆ Envelope() [1/6]

Envelope ( )

Default constructor.

Definition at line 54 of file envelope.hpp.

54{}

◆ Envelope() [2/6]

Envelope ( const string &  counterparty,
const string &  nettingSetId,
const set< string > &  portfolioIds = set<string>() 
)

Constructor with netting set id and portfolio ids, without additional fields.

Definition at line 57 of file envelope.hpp.

59 initialized_(true) {}
set< string > portfolioIds_
Definition: envelope.hpp:124
const set< string > & portfolioIds() const
Definition: envelope.hpp:103
NettingSetDetails nettingSetDetails_
Definition: envelope.hpp:123
const string & nettingSetId() const
Definition: envelope.hpp:101
const string & counterparty() const
Definition: envelope.hpp:100
Serializable object holding netting set identification data.

◆ Envelope() [3/6]

Envelope ( const string &  counterparty,
const NettingSetDetails nettingSetDetails = NettingSetDetails(),
const set< string > &  portfolioIds = set<string>() 
)

Constructor with netting set details and portfolio ids, without additional fields.

Definition at line 62 of file envelope.hpp.

◆ Envelope() [4/6]

Envelope ( const string &  counterparty,
const map< string, string > &  additionalFields 
)

Constructor without netting set / portfolio ids, with additional fields.

Definition at line 68 of file envelope.hpp.

70 for (const auto& addField : additionalFields)
71 additionalFields_[addField.first] = addField.second;
72 }
const map< string, string > additionalFields() const
Definition: envelope.cpp:110
map< string, boost::any > additionalFields_
Definition: envelope.hpp:125
+ Here is the call graph for this function:

◆ Envelope() [5/6]

Envelope ( const string &  counterparty,
const string &  nettingSetId,
const map< string, string > &  additionalFields,
const set< string > &  portfolioIds = set<string>() 
)

Constructor with netting set, with additional fields.

Definition at line 75 of file envelope.hpp.

78 initialized_(true) {
79 for (const auto& addField : additionalFields)
80 additionalFields_[addField.first] = addField.second;
81 }
+ Here is the call graph for this function:

◆ Envelope() [6/6]

Envelope ( const string &  counterparty,
const NettingSetDetails nettingSetDetails,
const map< string, string > &  additionalFields,
const set< string > &  portfolioIds = set<string>() 
)

Constructor with netting set details, with additional fields.

Definition at line 84 of file envelope.hpp.

87 initialized_(true) {
88 for (const auto& addField : additionalFields)
89 additionalFields_[addField.first] = addField.second;
90 }
+ Here is the call graph for this function:

Member Function Documentation

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Implements XMLSerializable.

Definition at line 27 of file envelope.cpp.

27 {
28 XMLUtils::checkNode(node, "Envelope");
29 counterparty_ = XMLUtils::getChildValue(node, "CounterParty", false);
30
31 XMLNode* nettingSetDetailsNode = XMLUtils::getChildNode(node, "NettingSetDetails");
32 if (nettingSetDetailsNode) {
33 nettingSetDetails_.fromXML(nettingSetDetailsNode);
34 } else {
35 string nettingSetId = XMLUtils::getChildValue(node, "NettingSetId", false);
37 }
38
39 portfolioIds_.clear();
40 XMLNode* portfolioNode = XMLUtils::getChildNode(node, "PortfolioIds");
41 if (portfolioNode) {
42 for (auto const& c : XMLUtils::getChildrenNodes(portfolioNode, "PortfolioId"))
44 }
45
46 std::function<boost::any(XMLNode*)> getValue;
47 getValue = [&getValue](XMLNode* node) {
48 boost::any value;
49 vector<XMLNode*> children = XMLUtils::getChildrenNodes(node, "");
50 // If node is a single-value node
51 if (children.size() == 1 && XMLUtils::getNodeName(children[0]) == "") {
53 } else {
54 std::multimap<string, boost::any> subAddFields;
55 for (XMLNode* child : children) {
56 const string& name = XMLUtils::getNodeName(child);
57 boost::any childValue = getValue(child);
58 subAddFields.insert({name, childValue});
59 }
60 value = subAddFields;
61 }
62 return value;
63 };
64
65 additionalFields_.clear();
66 XMLNode* additionalNode = XMLUtils::getChildNode(node, "AdditionalFields");
67 if (additionalNode) {
68 for (XMLNode* child = XMLUtils::getChildNode(additionalNode); child; child = XMLUtils::getNextSibling(child)) {
69 additionalFields_[XMLUtils::getNodeName(child)] = getValue(child);
70 }
71 }
72 initialized_ = true;
73}
virtual void fromXML(XMLNode *node) override
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 getNodeName(XMLNode *n)
Get and set a node's name.
Definition: xmlutils.cpp:473
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static string getNodeValue(XMLNode *node)
Get a node's value.
Definition: xmlutils.cpp:489
static XMLNode * getNextSibling(XMLNode *node, const string &name="")
Get a node's next sibling node.
Definition: xmlutils.cpp:484
SafeStack< ValueType > value
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
string name
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Implements XMLSerializable.

Definition at line 75 of file envelope.cpp.

75 {
76 XMLNode* node = doc.allocNode("Envelope");
77 XMLUtils::addChild(doc, node, "CounterParty", counterparty_);
79 XMLUtils::addChild(doc, node, "NettingSetId", nettingSetDetails_.nettingSetId());
80 } else {
82 }
83 XMLNode* portfolioNode = doc.allocNode("PortfolioIds");
84 XMLUtils::appendNode(node, portfolioNode);
85 for (const auto& p : portfolioIds_)
86 XMLUtils::addChild(doc, portfolioNode, "PortfolioId", p);
87 XMLNode* additionalNode = doc.allocNode("AdditionalFields");
88 XMLUtils::appendNode(node, additionalNode);
89
90 std::function<void(XMLNode*, const string&, const boost::any&)> addChild;
91 addChild = [&addChild, &doc](XMLNode* node, const string& name, const boost::any& val) {
92 if (val.type() == typeid(string)) {
93 XMLUtils::addChild(doc, node, name, boost::any_cast<string>(val));
94 } else {
95 QL_REQUIRE(val.type() == typeid(std::multimap<string, boost::any>),
96 "Additional field type must be either string or map<string, boost::any>");
97 XMLNode* childNode = doc.allocNode(name);
98 XMLUtils::appendNode(node, childNode);
99 for (const auto& kv : boost::any_cast<std::multimap<string, boost::any>>(val)) {
100 addChild(childNode, kv.first, kv.second);
101 }
102 }
103 };
104
105 for (const auto& it : additionalFields_)
106 addChild(additionalNode, it.first, it.second);
107 return node;
108}
virtual XMLNode * toXML(XMLDocument &doc) const override
const string & nettingSetId() const
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ counterparty()

const string & counterparty ( ) const

Definition at line 100 of file envelope.hpp.

100{ return counterparty_; }

◆ nettingSetId()

const string & nettingSetId ( ) const

Definition at line 101 of file envelope.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nettingSetDetails()

const NettingSetDetails nettingSetDetails ( ) const

Definition at line 102 of file envelope.hpp.

102{ return nettingSetDetails_; }

◆ portfolioIds()

const set< string > & portfolioIds ( ) const

Definition at line 103 of file envelope.hpp.

103{ return portfolioIds_; }
+ Here is the caller graph for this function:

◆ additionalFields()

const map< string, string > additionalFields ( ) const

Definition at line 110 of file envelope.cpp.

110 {
111 map<string, string> stringAddFields;
112 for (const auto& f : additionalFields_)
113 if (f.second.type() == typeid(string))
114 stringAddFields[f.first] = boost::any_cast<string>(f.second);
115 return stringAddFields;
116}
+ Here is the caller graph for this function:

◆ fullAdditionalFields()

const map< string, boost::any > & fullAdditionalFields ( ) const

Definition at line 105 of file envelope.hpp.

105{ return additionalFields_; }
+ Here is the caller graph for this function:

◆ additionalField()

string additionalField ( const std::string &  name,
const bool  mandatory = true,
const std::string &  defaultValue = std::string() 
) const

Definition at line 118 of file envelope.cpp.

118 {
119 auto af = additionalFields();
120 auto it = af.find(name);
121 QL_REQUIRE(it != af.end() || !mandatory,
122 "Envelope::additionalField(): Mandatory field '" << name << "' not found.");
123 return it == af.end() ? defaultValue : it->second;
124}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ additionalAnyField()

boost::any additionalAnyField ( const std::string &  name,
const bool  mandatory = true,
const boost::any &  defaultValue = boost::none 
) const

Definition at line 126 of file envelope.cpp.

126 {
127 auto it = additionalFields_.find(name);
128 QL_REQUIRE(it != additionalFields_.end() || !mandatory,
129 "Envelope::additionalField(): Mandatory field '" << name << "' not found.");
130 return it == additionalFields_.end() ? defaultValue : it->second;
131}

◆ setAdditionalField()

void setAdditionalField ( const std::string &  key,
const boost::any &  value 
)

Definition at line 133 of file envelope.cpp.

133 {
135}
+ Here is the caller graph for this function:

◆ initialized()

bool initialized ( ) const

Check if the envelope is initialized.

Definition at line 116 of file envelope.hpp.

116{ return initialized_; }
+ Here is the caller graph for this function:

◆ hasNettingSetDetails()

bool hasNettingSetDetails ( ) const

Check if the netting set details have been populated.

Definition at line 118 of file envelope.hpp.

118{ return !nettingSetDetails_.empty(); }
bool empty() const
Check if the netting set details have been populated.
+ Here is the call graph for this function:

Member Data Documentation

◆ counterparty_

string counterparty_
private

Definition at line 122 of file envelope.hpp.

◆ nettingSetDetails_

NettingSetDetails nettingSetDetails_
private

Definition at line 123 of file envelope.hpp.

◆ portfolioIds_

set<string> portfolioIds_
private

Definition at line 124 of file envelope.hpp.

◆ additionalFields_

map<string, boost::any> additionalFields_
private

Definition at line 125 of file envelope.hpp.

◆ initialized_

bool initialized_ = false
private

Definition at line 126 of file envelope.hpp.