PCMOutputNode.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "../include/PCMOutputNode.h"
00030
00031
00032
00033
00034
00035 #include "tinyxml/tinyxml.h"
00036
00037 namespace ParCompMark
00038 {
00039
00040
00041
00042
00043
00044 const std::string OutputNode::TEXTNODENAME = "#text";
00045
00046
00047
00048
00049
00050 OutputNode::OutputNode(const std::string & name, const NodeType & type):
00051
00052 Name(name
00053 ),
00054
00055 mType(type
00056 )
00057
00058
00059
00060
00061
00062 {
00063 Assert(_testXMLName(name), INVALID_OPERATION_ERROR, "OutputNode::OutputNode");
00064
00065
00066 }
00067
00068
00069
00070 OutputNode::OutputNode(const std::string & text):
00071
00072 Name(TEXTNODENAME
00073 ),
00074
00075 mType(OutputNode::TEXT
00076 ),
00077
00078 mText(text
00079 )
00080
00081
00082
00083
00084
00085 {
00086
00087 }
00088
00089
00090
00091 OutputNode::~OutputNode()
00092 {
00093
00094 }
00095
00096
00097
00098
00099
00100
00101
00102 OutputNode::Pointer OutputNode::parseFromXML(std::string & xmlDocument)
00103 {
00104
00109 OutputNode::Pointer root;
00110
00111 return root;
00112 }
00113
00114
00115
00116 bool OutputNode::_testXMLName(const std::string & name)
00117 {
00118
00119
00120 return true;
00121 }
00122
00123
00124
00125 std::string OutputNode::_convertSpecialChars(const std::string & string)
00126 {
00127
00128
00129 return string;
00130 }
00131
00132
00133
00134
00135
00136
00137
00138 OutputNode::Pointer OutputNode::createChildNode(const std::string & name, const NodeType & type)
00139 {
00140 Assert(mType != OutputNode::TEXT
00141 && mType != OutputNode::CDATA, INVALID_OPERATION_ERROR, "OutputNode::createChildNode");
00142
00143
00144 OutputNode::Pointer child(new OutputNode(name, type));
00145 mChildren.push_back(child);
00146
00147 return child;
00148 }
00149
00150
00151
00152 OutputNode::Pointer OutputNode::createChildNode(const std::string & text)
00153 {
00154 Assert(mType != OutputNode::TEXT
00155 && mType != OutputNode::CDATA, INVALID_OPERATION_ERROR, "OutputNode::createChildNode");
00156
00157
00158 OutputNode::Pointer child(new OutputNode(text));
00159 mChildren.push_back(child);
00160
00161 return child;
00162 }
00163
00164
00165
00166 void OutputNode::addChildNode(OutputNode::Pointer child)
00167 {
00168 Assert(mType != OutputNode::TEXT
00169 && mType != OutputNode::CDATA, INVALID_OPERATION_ERROR, "OutputNode::addChildNode");
00170 Assert(child.getPtr() != this, INVALID_OPERATION_ERROR, "OutputNode::addChildNode");
00171
00172
00173 mChildren.push_back(child);
00174 }
00175
00176
00177
00178 u32 OutputNode::getChildCount()
00179 {
00180 return mChildren.size();
00181 }
00182
00183
00184
00185 OutputNode::Pointer OutputNode::getFirstChildNode()
00186 {
00187 Assert(mType != OutputNode::TEXT && mType != OutputNode::CDATA
00188 && mChildren.size(), INVALID_OPERATION_ERROR, "OutputNode::getFirstChild");
00189 return mChildren.front();
00190 }
00191
00192
00193
00194 bool OutputNode::hasAttribute(const std::string & attribute) const
00195 {
00196 Assert(mType != OutputNode::TEXT
00197 && mType != OutputNode::CDATA, INVALID_OPERATION_ERROR, "OutputNode::hasAttribute");
00198 return mAttributes.find(attribute) != mAttributes.end();
00199 }
00200
00201
00202
00203 const std::string & OutputNode::getAttribute(const std::string & attribute) const
00204 {
00205 Assert(mType != OutputNode::TEXT
00206 && mType != OutputNode::CDATA, INVALID_OPERATION_ERROR, "OutputNode::getAttribute");
00207 AttributeMapIterator i = mAttributes.find(attribute);
00208
00209
00210 Assert(i != mAttributes.end(), INVALID_NAME_ERROR, "OutputNode::getAttribute");
00211
00212 return i->second;
00213 }
00214
00215
00216
00217 void OutputNode::setAttribute(const std::string & attribute, const std::string & value)
00218 {
00219 Assert(_testXMLName(attribute), INVALID_OPERATION_ERROR, "OutputNode::setAttribute");
00220 Assert(mType != OutputNode::TEXT
00221 && mType != OutputNode::CDATA, INVALID_OPERATION_ERROR, "OutputNode::createAttribute");
00222
00223 mAttributes[attribute] = value;
00224 }
00225
00226
00227
00228 std::ostringstream & OutputNode::serialize2XML(std::ostringstream & osstr)
00229 {
00230
00231
00232 if(mType == OutputNode::TEXT)
00233 {
00234 osstr << mText;
00235 } else if(mType == OutputNode::CDATA)
00236 {
00237 osstr << "<![CDATA[" << mText << "]]>";
00238 }
00239
00240 else
00241 {
00242
00243
00244 std::string xmlNameSpace;
00245
00246 switch (mType)
00247 {
00248 case OutputNode::DEFINITION:
00249 xmlNameSpace = "def:";
00250 break;
00251 case OutputNode::INFORMATION:
00252 xmlNameSpace = "info:";
00253 break;
00254 case OutputNode::REFERENCE:
00255 xmlNameSpace = "ref:";
00256 break;
00257 case OutputNode::STATISTICS:
00258 xmlNameSpace = "stat:";
00259 break;
00260 default:
00261 xmlNameSpace = "";
00262 }
00263
00264 osstr << '<' << xmlNameSpace;
00265
00266
00267 osstr << mName;
00268
00269
00270 for(AttributeMapIterator i = mAttributes.begin(); i != mAttributes.end(); i++)
00271 osstr << ' ' << i->first << "=\"" << _convertSpecialChars(i->second) << '\"';
00272
00273
00274 if(mChildren.size())
00275 {
00276 osstr << ">";
00277 for(ChildNodeListIterator i = mChildren.begin(); i != mChildren.end(); i++)
00278 (*i).getPtr()->serialize2XML(osstr);
00279 osstr << "</" << xmlNameSpace << mName << ">";
00280 } else
00281 {
00282 osstr << "/>";
00283 }
00284 }
00285
00286
00287 Assert(!osstr.bad(), INVALID_OPERATION_ERROR, "OutputNode::serialize2XML");
00288
00289 return osstr;
00290 }
00291
00292
00293
00294 std::string OutputNode::serialize2XML()
00295 {
00296 std::ostringstream osstr;
00297 return serialize2XML(osstr).str();
00298 }
00299
00300
00301
00302 void OutputNode::refreshData()
00303 {
00304
00305 }
00306
00307
00308
00309 void OutputNode::clean()
00310 {
00311 for(ChildNodeListIterator i = mChildren.begin(); i != mChildren.end(); i++)
00312 {
00313
00314 i->getPtr()->clean();
00315
00316 i->kill();
00317
00318 }
00319
00320 mChildren.clear();
00321
00322 }
00323
00324
00325
00326 }