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