blob: e31d7720578ee47a788aa184ac8e1cf921c132f6 [file] [log] [blame]
Patrick Benavoli68a91282011-08-31 11:23:23 +02001/* <auto_header>
2 * <FILENAME>
3 *
4 * INTEL CONFIDENTIAL
5 * Copyright © 2011 Intel
6 * Corporation All Rights Reserved.
7 *
8 * The source code contained or described herein and all documents related to
9 * the source code ("Material") are owned by Intel Corporation or its suppliers
10 * or licensors. Title to the Material remains with Intel Corporation or its
11 * suppliers and licensors. The Material contains trade secrets and proprietary
12 * and confidential information of Intel or its suppliers and licensors. The
13 * Material is protected by worldwide copyright and trade secret laws and
14 * treaty provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed, or
16 * disclosed in any way without Intel’s prior express written permission.
17 *
18 * No license under any patent, copyright, trade secret or other intellectual
19 * property right is granted to or conferred upon you by disclosure or delivery
20 * of the Materials, either expressly, by implication, inducement, estoppel or
21 * otherwise. Any license under such intellectual property rights must be
22 * express and approved by Intel in writing.
23 *
24 * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
25 * CREATED: 2011-06-01
26 * UPDATED: 2011-07-27
27 *
28 *
29 * </auto_header>
30 */
31#pragma once
32
33#include <string>
34#include <vector>
35#include <stdint.h>
36#include "XmlSink.h"
37#include "XmlSource.h"
38
39#include "PathNavigator.h"
40
41using namespace std;
42
43class CXmlElementSerializingContext;
44class CErrorContext;
45
46class CElement : public IXmlSink, public IXmlSource
47{
48 friend class CAutoLog;
49public:
50 CElement(const string& strName = "");
51 virtual ~CElement();
52
53 // Logging
54 void log(const string& strMessage, ...) const;
55
56 // Description
57 void setDescription(const string& strDescription);
58 const string& getDescription() const;
59
60 // Name / Path
61 const string& getName() const;
62 bool rename(const string& strName, string& strError);
63 string getPath() const;
64 string getQualifiedPath() const;
65
66 // Creation / build
67 virtual bool init(string& strError);
68 virtual void clean();
69
70 // Children management
71 void addChild(CElement* pChild);
72 bool removeChild(CElement* pChild);
73 void listChildren(string& strChildList) const;
74 string listQualifiedPaths(bool bDive, uint32_t uiLevel = 0) const;
75 void listChildrenPaths(string& strChildPathList) const;
76
77 // Hierarchy query
78 uint32_t getNbChildren() const;
79 CElement* findChildOfKind(const string& strKind);
80 const CElement* findChildOfKind(const string& strKind) const;
81 const CElement* getParent() const;
82 const CElement* getChild(uint32_t uiIndex) const;
83 CElement* getChild(uint32_t uiIndex);
84 const CElement* findChild(const string& strName) const;
85 CElement* findChild(const string& strName);
86 const CElement* findDescendant(CPathNavigator& pathNavigator) const;
87 CElement* findDescendant(CPathNavigator& pathNavigator);
88 bool isDescendantOf(const CElement* pCandidateAscendant) const;
89
90 // From IXmlSink
91 virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
92
93 // From IXmlSource
94 virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
95
96 // Content structure dump
97 void dumpContent(string& strContent, CErrorContext& errorContext, const uint32_t uiDepth = 0) const;
98
99 // Checksum for integrity checks
100 uint8_t computeStructureChecksum() const;
101
102 // Class kind
103 virtual string getKind() const = 0;
104protected:
105 // Content dumping
106 virtual void logValue(string& strValue, CErrorContext& errorContext) const;
107 // Name setting
108 void setName(const string& strName);
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200109 // Utility to underline
110 static void appendTitle(string& strTo, const string& strTitle);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200111
112 // Hierarchy
113 CElement* getLastChild();
114 CElement* getParent();
115 CElement* findAscendantOfKind(const string& strKind);
116 CElement* getRoot();
117 const CElement* getRoot() const;
118private:
119 // Logging (done by root)
120 virtual void doLog(const string& strLog) const;
121 virtual void nestLog() const;
122 virtual void unnestLog() const;
123 // Returns Name or Kind if no Name
124 string getPathName() const;
125 // Returns true if children dynamic creation is to be dealt with
126 virtual bool childrenAreDynamic() const;
127 // House keeping
128 void removeChildren();
129 // For logging
130 uint32_t getDepth() const;
131 // Fill XmlElement during XML composing
132 void setXmlNameAttribute(CXmlElement& xmlElement) const;
133
134 // Name
135 string _strName;
136
137 // Description
138 string _strDescription;
139
140 // Child iterators
141 typedef vector<CElement*>::iterator ChildArrayIterator;
142 typedef vector<CElement*>::reverse_iterator ChildArrayReverseIterator;
143 // Children
144 vector<CElement*> _childArray;
145 // Parent
146 CElement* _pParent;
147};