12#include <Poco/DOM/AutoPtr.h>
13#include <Poco/DOM/DOMParser.h>
14#include <Poco/DOM/DOMWriter.h>
15#include <Poco/DOM/Document.h>
16#include <Poco/DOM/Element.h>
17#include <Poco/DOM/Text.h>
18#include <boost/algorithm/string.hpp>
19#include <boost/format.hpp>
20#include <boost/functional/hash.hpp>
29template <
typename CheckDimensionPolicy>
33 const std::string dimensionId = dimensionToAdd->getDimensionId();
35 std::find_if(m_vecDimensions.cbegin(), m_vecDimensions.cend(),
37 if (location == m_vecDimensions.cend()) {
38 m_vecDimensions.emplace_back(std::move(dimensionToAdd));
50template <
typename CheckDimensionPolicy>
52 for (
auto &manyDim : manyDims) {
53 addOrdinaryDimension(manyDim);
57template <
typename CheckDimensionPolicy>
60 : m_vecDimensions(other.m_vecDimensions), m_spXDimension(other.m_spXDimension),
61 m_spYDimension(other.m_spYDimension), m_spZDimension(other.m_spZDimension), m_spTDimension(other.m_spTDimension),
62 m_changed(other.m_changed), m_lastResult(other.m_lastResult) {}
64template <
typename CheckDimensionPolicy>
68 m_vecDimensions = other.m_vecDimensions;
69 m_spXDimension = other.m_spXDimension;
70 m_spYDimension = other.m_spYDimension;
71 m_spZDimension = other.m_spZDimension;
72 m_spTDimension = other.m_spTDimension;
73 m_changed = other.m_changed;
74 m_lastResult = other.m_lastResult;
84template <
typename CheckDimensionPolicy>
86 CheckDimensionPolicy policy;
87 policy(dimensionToAdd);
95template <
typename CheckDimensionPolicy>
100 applyPolicyChecking(*dimension);
101 addOrdinaryDimension(dimension);
102 m_spXDimension = dimension;
114template <
typename CheckDimensionPolicy>
119 applyPolicyChecking(*dimension);
120 addOrdinaryDimension(dimension);
121 m_spYDimension = dimension;
133template <
typename CheckDimensionPolicy>
137 applyPolicyChecking(*dimension);
138 addOrdinaryDimension(dimension);
139 m_spZDimension = dimension;
151template <
typename CheckDimensionPolicy>
156 applyPolicyChecking(*dimension);
157 addOrdinaryDimension(dimension);
158 m_spTDimension = dimension;
173 AutoPtr<Document> pDoc =
new Document;
174 AutoPtr<Element> dimensionSetElement = pDoc->createElement(
"DimensionSet");
175 pDoc->appendChild(dimensionSetElement);
178 std::string dimensionXMLString;
180 for (
auto it = m_vecDimensions.begin(); it != m_vecDimensions.end(); ++it) {
181 dimensionXMLString += (*it)->toXMLString();
185 AutoPtr<Text> percents = pDoc->createTextNode(
"%s");
186 dimensionSetElement->appendChild(percents);
189 AutoPtr<Element> xDimensionElement = pDoc->createElement(
"XDimension");
190 AutoPtr<Element> xDimensionIdElement = pDoc->createElement(
"RefDimensionId");
191 if (hasXDimension()) {
192 std::string xDimensionId = this->m_spXDimension->getDimensionId();
193 AutoPtr<Text> idXText = pDoc->createTextNode(xDimensionId);
194 xDimensionIdElement->appendChild(idXText);
196 xDimensionElement->appendChild(xDimensionIdElement);
197 dimensionSetElement->appendChild(xDimensionElement);
200 AutoPtr<Element> yDimensionElement = pDoc->createElement(
"YDimension");
201 AutoPtr<Element> yDimensionIdElement = pDoc->createElement(
"RefDimensionId");
202 if (hasYDimension()) {
203 std::string yDimensionId = this->m_spYDimension->getDimensionId();
204 AutoPtr<Text> idYText = pDoc->createTextNode(yDimensionId);
205 yDimensionIdElement->appendChild(idYText);
207 yDimensionElement->appendChild(yDimensionIdElement);
208 dimensionSetElement->appendChild(yDimensionElement);
211 AutoPtr<Element> zDimensionElement = pDoc->createElement(
"ZDimension");
212 AutoPtr<Element> zDimensionIdElement = pDoc->createElement(
"RefDimensionId");
213 if (hasZDimension()) {
214 std::string zDimensionId = this->m_spZDimension->getDimensionId();
215 AutoPtr<Text> idZText = pDoc->createTextNode(zDimensionId);
216 zDimensionIdElement->appendChild(idZText);
218 zDimensionElement->appendChild(zDimensionIdElement);
219 dimensionSetElement->appendChild(zDimensionElement);
222 AutoPtr<Element> tDimensionElement = pDoc->createElement(
"TDimension");
223 AutoPtr<Element> tDimensionIdElement = pDoc->createElement(
"RefDimensionId");
224 if (hasTDimension()) {
225 std::string tDimensionId = this->m_spTDimension->getDimensionId();
226 AutoPtr<Text> idTText = pDoc->createTextNode(tDimensionId);
227 tDimensionIdElement->appendChild(idTText);
229 tDimensionElement->appendChild(tDimensionIdElement);
230 dimensionSetElement->appendChild(tDimensionElement);
232 std::stringstream xmlstream;
234 writer.writeNode(xmlstream, pDoc);
236 m_lastResult = boost::str(boost::format(xmlstream.str().c_str()) % dimensionXMLString.c_str());
243 return nullptr != this->m_spXDimension.get();
247 return nullptr != this->m_spYDimension.get();
251 return nullptr != this->m_spZDimension.get();
255 return nullptr != this->m_spTDimension.get();
258template <
typename CheckDimensionPolicy>
260 return hasTDimension() && this->m_spTDimension->getIsIntegrated();
266template <
typename CheckDimensionPolicy>
The class describes one dimension of multidimensional dataset representing an orthogonal dimension an...
bool addXDimension(const IMDDimension_const_sptr &dimension) const
Add x dimension.
bool hasZDimension() const
Determine whether a valid z dimension has been provided.
bool addZDimension(const IMDDimension_const_sptr &dimension) const
Add z dimension.
bool hasTDimension() const
Determine whether a valid t dimension has been provided.
bool addYDimension(const IMDDimension_const_sptr &dimension) const
Add y dimension.
void addManyOrdinaryDimensions(const VecIMDDimension_sptr &manyDims) const
Add many ordinary dimensions.
bool hasIntegratedTDimension() const
Determine whether an integrated t dimension has been provided.
bool addTDimension(const IMDDimension_const_sptr &dimension) const
Add t dimension.
void applyPolicyChecking(const IMDDimension &dimensionToAdd) const
Instantiate and apply the checking policy.
bool hasXDimension() const
Determine if a valid x dimension has been provided.
MDGeometryBuilderXML()
Constructor.
const std::string & create() const
Create the xml.
MDGeometryBuilderXML & operator=(const MDGeometryBuilderXML &)
Assignment Operator.
~MDGeometryBuilderXML()
Destructor.
bool addOrdinaryDimension(IMDDimension_const_sptr dimensionToAdd) const
Add a dimension that is neither considered x, y, z or t.
bool hasYDimension() const
Determine whether a valid y dimension has been provided.
std::vector< IMDDimension_sptr > VecIMDDimension_sptr
Vector of shared pointers to IMDDimensions.
std::shared_ptr< const IMDDimension > IMDDimension_const_sptr
Shared Pointer to const IMDDimension.