blob: 0e592d6c32d4b43f20602eef993601de6b1f4c3b [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);
Patrick Benavoliee65e6d2011-11-20 18:52:24 +0100106 static string toString(double dValue);
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200107
Patrick Benavoli68a91282011-08-31 11:23:23 +0200108 // Checksum for integrity checks
109 uint8_t computeStructureChecksum() const;
110
111 // Class kind
112 virtual string getKind() const = 0;
113protected:
114 // Content dumping
115 virtual void logValue(string& strValue, CErrorContext& errorContext) const;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200116 // Utility to underline
117 static void appendTitle(string& strTo, const string& strTitle);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200118
119 // Hierarchy
120 CElement* getLastChild();
121 CElement* getParent();
122 CElement* findAscendantOfKind(const string& strKind);
123 CElement* getRoot();
124 const CElement* getRoot() const;
125private:
126 // Logging (done by root)
127 virtual void doLog(const string& strLog) const;
128 virtual void nestLog() const;
129 virtual void unnestLog() const;
130 // Returns Name or Kind if no Name
131 string getPathName() const;
132 // Returns true if children dynamic creation is to be dealt with
133 virtual bool childrenAreDynamic() const;
134 // House keeping
135 void removeChildren();
136 // For logging
137 uint32_t getDepth() const;
138 // Fill XmlElement during XML composing
139 void setXmlNameAttribute(CXmlElement& xmlElement) const;
140
141 // Name
142 string _strName;
143
144 // Description
145 string _strDescription;
146
147 // Child iterators
148 typedef vector<CElement*>::iterator ChildArrayIterator;
149 typedef vector<CElement*>::reverse_iterator ChildArrayReverseIterator;
150 // Children
151 vector<CElement*> _childArray;
152 // Parent
153 CElement* _pParent;
154};