#include <XMLObjectWriter.h>
Inheritance diagram for vpr::XMLObjectWriter:


Public Methods | |
| XMLObjectWriter () | |
| XMLObjectWriter (cppdom::NodePtr rootNode, cppdom::Node *curNode) | |
| std::vector< vpr::Uint8 > | getData () |
| Get the data buffer. More... | |
| cppdom::NodePtr | getRootNode () |
| virtual vpr::ReturnStatus | writeUint8 (vpr::Uint8 val) |
| virtual vpr::ReturnStatus | writeUint16 (vpr::Uint16 val) |
| virtual vpr::ReturnStatus | writeUint32 (vpr::Uint32 val) |
| virtual vpr::ReturnStatus | writeUint64 (vpr::Uint64 val) |
| virtual vpr::ReturnStatus | writeFloat (float val) |
| virtual vpr::ReturnStatus | writeDouble (double val) |
| virtual vpr::ReturnStatus | writeString (std::string val) |
| virtual vpr::ReturnStatus | writeBool (bool val) |
Tag and attribute handling | |
| virtual vpr::ReturnStatus | beginTag (std::string tagName) |
| Starts a new section/element of name tagName. More... | |
| virtual vpr::ReturnStatus | endTag () |
| Ends the most recently named tag. More... | |
| virtual vpr::ReturnStatus | beginAttribute (std::string attributeName) |
| Starts an attribute of the name attributeName. More... | |
| virtual vpr::ReturnStatus | endAttribute () |
| Ends the most recently named attribute. More... | |
Protected Types | |
| enum | CurTarget { AttribTarget, CdataTarget } |
Protected Methods | |
| template<class T> vpr::ReturnStatus | writeValueStringRep (const T &val) |
| Helper to write the data to the current string. More... | |
Protected Attributes | |
| cppdom::NodePtr | mRootNode |
| Base node of the tree. More... | |
| cppdom::Node * | mCurNode |
| Element we are currently working with. More... | |
| std::string | mCurCData |
| Temporary place to store the value of the current cdata. More... | |
| std::string | mCurAttribData |
| Temporary place to store the current attribute data. More... | |
| std::string | mCurAttribName |
| The name of the current attribute we are working on. More... | |
| CurTarget | mCurTarget |
| Are we currently writing to attributes or cdata. More... | |
Write directly to a data buffer.
Definition at line 63 of file XMLObjectWriter.h.
|
|
Definition at line 111 of file XMLObjectWriter.h.
00112 { AttribTarget,
00113 CdataTarget
00114 };
|
|
|
Definition at line 66 of file XMLObjectWriter.h. References CdataTarget, mCurNode, and mCurTarget.
00067 : mCurNode(NULL), mCurTarget(CdataTarget) 00068 {;} |
|
||||||||||||
|
Definition at line 70 of file XMLObjectWriter.h. References CdataTarget, mCurNode, mCurTarget, and mRootNode.
00071 : mCurTarget(CdataTarget) 00072 { 00073 mRootNode = rootNode; 00074 mCurNode = curNode; 00075 } |
|
|
Get the data buffer. Return the data buffer representation of the current object tree Definition at line 156 of file XMLObjectWriter.h. References mRootNode, and vprASSERT.
|
|
|
Definition at line 82 of file XMLObjectWriter.h. References mRootNode.
00083 { return mRootNode; }
|
|
|
Starts a new section/element of name tagName. When mCurNode is Null, then we need to allocated a new node in its place. And also check the Root node to set it to (this is the first call to beginTag) Implements vpr::ObjectWriter. Definition at line 170 of file XMLObjectWriter.h. References mCurCData, mCurNode, mRootNode, vpr::ReturnStatus::Succeed, and vprASSERT.
00171 {
00172 cppdom::NodePtr new_node;
00173
00174 if(mCurNode == NULL) // First node created, so initialize everything
00175 {
00176 cppdom::ContextPtr cxt(new cppdom::Context);
00177 new_node = cppdom::NodePtr(new cppdom::Node(tagName, cxt));
00178 vprASSERT(mRootNode.get() == NULL && "Tried to root the writer twice");
00179 mRootNode = new_node;
00180 mCurNode = new_node.get();
00181 }
00182 else // Create new child of current node
00183 {
00184 // Check for pending cdata to write
00185 // - If there is some, then write it out
00186 if(!mCurCData.empty())
00187 {
00188 mCurNode->setCdata(mCurCData);
00189 mCurCData.clear();
00190 }
00191
00192 // Add new child node
00193 new_node = cppdom::NodePtr(new cppdom::Node(tagName, mRootNode->getContext()));
00194 mCurNode->addChild(new_node);
00195 mCurNode = new_node.get();
00196 }
00197 return vpr::ReturnStatus::Succeed;
00198 }
|
|
|
Ends the most recently named tag. Close off the current node and set current to it's parent. Implements vpr::ObjectWriter. Definition at line 203 of file XMLObjectWriter.h. References mCurCData, mCurNode, vpr::ReturnStatus::Succeed, and vprASSERT.
00204 {
00205 vprASSERT(mCurNode != NULL);
00206 //vprASSERT(mCurNode->getParent() != NULL);
00207
00208 // Write out the cdata
00209 if(!mCurCData.empty())
00210 {
00211 mCurNode->setCdata(mCurCData);
00212 mCurCData.clear();
00213 }
00214
00215 cppdom::Node* cur_parent = mCurNode->getParent(); // Get cur node's parent node
00216 mCurNode = cur_parent; // Set to new current node
00217
00218 // If it had some cdata, then get it to initialize the current cdata
00219 // so we can write more data to it
00220 if(NULL != mCurNode)
00221 {
00222 mCurCData = mCurNode->getCdata();
00223 }
00224
00225 return vpr::ReturnStatus::Succeed;
00226 }
|
|
|
Starts an attribute of the name attributeName.
Implements vpr::ObjectWriter. Definition at line 229 of file XMLObjectWriter.h. References AttribTarget, mCurAttribData, mCurAttribName, mCurTarget, vpr::ReturnStatus::Succeed, and vprASSERT.
00230 {
00231 // Make sure that we have not called beginAttribute without an endAttribute
00232 vprASSERT(mCurAttribName.empty() && "Didn't close previous attribute");
00233 vprASSERT(mCurAttribData.empty() && "There should not be any attribute data now. It should have been flushed");
00234
00235 mCurAttribName = attributeName;
00236 mCurTarget = AttribTarget;
00237 return vpr::ReturnStatus::Succeed;
00238 }
|
|
|
Ends the most recently named attribute.
Implements vpr::ObjectWriter. Definition at line 241 of file XMLObjectWriter.h. References AttribTarget, CdataTarget, mCurAttribData, mCurAttribName, mCurNode, mCurTarget, vpr::ReturnStatus::Succeed, and vprASSERT.
00242 {
00243 vprASSERT(AttribTarget == mCurTarget);
00244
00245 mCurNode->setAttribute(mCurAttribName, mCurAttribData);
00246 //std::cout << "Setting attrib:[" << mCurAttribName << "] value:[" << mCurAttribData << "]\n";
00247
00248 mCurAttribName.clear();
00249 mCurAttribData.clear();
00250
00251 mCurTarget = CdataTarget;
00252
00253 return vpr::ReturnStatus::Succeed;
00254 }
|
|
|
Implements vpr::ObjectWriter. Definition at line 260 of file XMLObjectWriter.h. References writeValueStringRep.
00261 {
00262 // Cast to uint16 so it doesn't get written as a char
00263 return writeValueStringRep(vpr::Uint16(val));
00264 }
|
|
|
Implements vpr::ObjectWriter. Definition at line 266 of file XMLObjectWriter.h. References writeValueStringRep.
00267 {
00268 return writeValueStringRep(val);
00269 }
|
|
|
Implements vpr::ObjectWriter. Definition at line 271 of file XMLObjectWriter.h. References writeValueStringRep.
00272 {
00273 return writeValueStringRep(val);
00274 }
|
|
|
Implements vpr::ObjectWriter. Definition at line 276 of file XMLObjectWriter.h. References writeValueStringRep.
00277 {
00278 return writeValueStringRep(val);
00279 }
|
|
|
Implements vpr::ObjectWriter. Definition at line 281 of file XMLObjectWriter.h. References writeValueStringRep.
00282 {
00283 return writeValueStringRep(val);
00284 }
|
|
|
Implements vpr::ObjectWriter. Definition at line 286 of file XMLObjectWriter.h. References writeValueStringRep.
00287 {
00288 return writeValueStringRep(val);
00289 }
|
|
|
Implements vpr::ObjectWriter. Definition at line 291 of file XMLObjectWriter.h. References AttribTarget, mCurAttribData, mCurCData, mCurTarget, vpr::ReturnStatus::Succeed, and vprASSERT.
00292 {
00293 if(AttribTarget == mCurTarget)
00294 {
00295 vprASSERT(mCurAttribData.empty() && "Can't add string to non-empty attribute");
00296 mCurAttribData = val;
00297 }
00298 else
00299 {
00300 if(!mCurCData.empty()) // Add spacing
00301 mCurCData += ' ';
00302 mCurCData += '"' + val + '"'; // Add string in quotes
00303 }
00304
00305 return vpr::ReturnStatus::Succeed;
00306 }
|
|
|
Implements vpr::ObjectWriter. Definition at line 308 of file XMLObjectWriter.h. References writeValueStringRep.
00309 {
00310 return writeValueStringRep(val);
00311 }
|
|
||||||||||
|
Helper to write the data to the current string.
Definition at line 118 of file XMLObjectWriter.h. References AttribTarget, mCurAttribData, mCurCData, mCurTarget, and vpr::ReturnStatus::Succeed. Referenced by writeBool, writeDouble, writeFloat, writeUint16, writeUint32, writeUint64, and writeUint8.
00119 {
00120 std::ostringstream oss;
00121 oss << val;
00122 if(AttribTarget == mCurTarget)
00123 {
00124 if(!mCurAttribData.empty()) // Add spacing
00125 { mCurAttribData += ' '; }
00126 mCurAttribData += oss.str();
00127 //std::cout << "writingValueStringRep: Attrib\nval:" << val << std::endl
00128 // << "str rep:" << oss.str() << std::endl
00129 // << "new attrib data:" << mCurAttribData << std::endl;
00130 }
00131 else
00132 {
00133 if(!mCurCData.empty()) // Add spacing
00134 { mCurCData += ' '; }
00135 mCurCData += oss.str();
00136 //std::cout << "writingValueStringRep: Cdata\nval:" << val << std::endl
00137 // << "str rep:" << oss.str() << std::endl
00138 // << "new cdata data:" << mCurCData << std::endl;
00139 }
00140
00141 return vpr::ReturnStatus::Succeed;
00142 }
|
|
|
Base node of the tree.
Definition at line 148 of file XMLObjectWriter.h. Referenced by beginTag, getData, getRootNode, and XMLObjectWriter. |
|
|
Element we are currently working with. (ptr since getParent is weak) Definition at line 149 of file XMLObjectWriter.h. Referenced by beginTag, endAttribute, endTag, and XMLObjectWriter. |
|
|
Temporary place to store the value of the current cdata.
Definition at line 150 of file XMLObjectWriter.h. Referenced by beginTag, endTag, writeString, and writeValueStringRep. |
|
|
Temporary place to store the current attribute data.
Definition at line 151 of file XMLObjectWriter.h. Referenced by beginAttribute, endAttribute, writeString, and writeValueStringRep. |
|
|
The name of the current attribute we are working on.
Definition at line 152 of file XMLObjectWriter.h. Referenced by beginAttribute, and endAttribute. |
|
|
Are we currently writing to attributes or cdata.
Definition at line 153 of file XMLObjectWriter.h. Referenced by beginAttribute, endAttribute, writeString, writeValueStringRep, and XMLObjectWriter. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002