blob: b3c3060470d18fc857d90231c51d3c017b03ad1d [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);
109
110 // Hierarchy
111 CElement* getLastChild();
112 CElement* getParent();
113 CElement* findAscendantOfKind(const string& strKind);
114 CElement* getRoot();
115 const CElement* getRoot() const;
116private:
117 // Logging (done by root)
118 virtual void doLog(const string& strLog) const;
119 virtual void nestLog() const;
120 virtual void unnestLog() const;
121 // Returns Name or Kind if no Name
122 string getPathName() const;
123 // Returns true if children dynamic creation is to be dealt with
124 virtual bool childrenAreDynamic() const;
125 // House keeping
126 void removeChildren();
127 // For logging
128 uint32_t getDepth() const;
129 // Fill XmlElement during XML composing
130 void setXmlNameAttribute(CXmlElement& xmlElement) const;
131
132 // Name
133 string _strName;
134
135 // Description
136 string _strDescription;
137
138 // Child iterators
139 typedef vector<CElement*>::iterator ChildArrayIterator;
140 typedef vector<CElement*>::reverse_iterator ChildArrayReverseIterator;
141 // Children
142 vector<CElement*> _childArray;
143 // Parent
144 CElement* _pParent;
145};