blob: af4fc33265b6345e4737dbf61610eff5b7099c0b [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;
Patrick Benavoli95ac0342011-11-07 20:32:51 +010062 void setName(const string& strName);
Patrick Benavoli68a91282011-08-31 11:23:23 +020063 bool rename(const string& strName, string& strError);
64 string getPath() const;
65 string getQualifiedPath() const;
66
67 // Creation / build
68 virtual bool init(string& strError);
69 virtual void clean();
70
71 // Children management
72 void addChild(CElement* pChild);
73 bool removeChild(CElement* pChild);
74 void listChildren(string& strChildList) const;
75 string listQualifiedPaths(bool bDive, uint32_t uiLevel = 0) const;
76 void listChildrenPaths(string& strChildPathList) const;
77
78 // Hierarchy query
79 uint32_t getNbChildren() const;
80 CElement* findChildOfKind(const string& strKind);
81 const CElement* findChildOfKind(const string& strKind) const;
82 const CElement* getParent() const;
83 const CElement* getChild(uint32_t uiIndex) const;
84 CElement* getChild(uint32_t uiIndex);
85 const CElement* findChild(const string& strName) const;
86 CElement* findChild(const string& strName);
87 const CElement* findDescendant(CPathNavigator& pathNavigator) const;
88 CElement* findDescendant(CPathNavigator& pathNavigator);
89 bool isDescendantOf(const CElement* pCandidateAscendant) const;
90
91 // From IXmlSink
92 virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
93
94 // From IXmlSource
95 virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
96
97 // Content structure dump
98 void dumpContent(string& strContent, CErrorContext& errorContext, const uint32_t uiDepth = 0) const;
99
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200100 // Element properties
101 virtual void showProperties(string& strResult) const;
102
103 // Conversion utilities
104 static string toString(uint32_t uiValue);
105 static string toString(int32_t iValue);
106
Patrick Benavoli68a91282011-08-31 11:23:23 +0200107 // Checksum for integrity checks
108 uint8_t computeStructureChecksum() const;
109
110 // Class kind
111 virtual string getKind() const = 0;
112protected:
113 // Content dumping
114 virtual void logValue(string& strValue, CErrorContext& errorContext) const;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200115 // Utility to underline
116 static void appendTitle(string& strTo, const string& strTitle);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200117
118 // Hierarchy
119 CElement* getLastChild();
120 CElement* getParent();
121 CElement* findAscendantOfKind(const string& strKind);
122 CElement* getRoot();
123 const CElement* getRoot() const;
124private:
125 // Logging (done by root)
126 virtual void doLog(const string& strLog) const;
127 virtual void nestLog() const;
128 virtual void unnestLog() const;
129 // Returns Name or Kind if no Name
130 string getPathName() const;
131 // Returns true if children dynamic creation is to be dealt with
132 virtual bool childrenAreDynamic() const;
133 // House keeping
134 void removeChildren();
135 // For logging
136 uint32_t getDepth() const;
137 // Fill XmlElement during XML composing
138 void setXmlNameAttribute(CXmlElement& xmlElement) const;
139
140 // Name
141 string _strName;
142
143 // Description
144 string _strDescription;
145
146 // Child iterators
147 typedef vector<CElement*>::iterator ChildArrayIterator;
148 typedef vector<CElement*>::reverse_iterator ChildArrayReverseIterator;
149 // Children
150 vector<CElement*> _childArray;
151 // Parent
152 CElement* _pParent;
153};