blob: d8701454d691df2041ed181e7ab2466153b253a2 [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
Kevin Rocardace81f82012-12-11 16:19:17 +010048 void log_info(const string& strMessage, ...) const;
49 void log_warning(const string& strMessage, ...) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020050
51 // Description
52 void setDescription(const string& strDescription);
53 const string& getDescription() const;
54
55 // Name / Path
56 const string& getName() const;
Patrick Benavoli95ac0342011-11-07 20:32:51 +010057 void setName(const string& strName);
Patrick Benavoli68a91282011-08-31 11:23:23 +020058 bool rename(const string& strName, string& strError);
59 string getPath() const;
60 string getQualifiedPath() const;
61
62 // Creation / build
63 virtual bool init(string& strError);
64 virtual void clean();
65
66 // Children management
67 void addChild(CElement* pChild);
68 bool removeChild(CElement* pChild);
69 void listChildren(string& strChildList) const;
70 string listQualifiedPaths(bool bDive, uint32_t uiLevel = 0) const;
71 void listChildrenPaths(string& strChildPathList) const;
72
73 // Hierarchy query
74 uint32_t getNbChildren() const;
75 CElement* findChildOfKind(const string& strKind);
76 const CElement* findChildOfKind(const string& strKind) const;
77 const CElement* getParent() const;
78 const CElement* getChild(uint32_t uiIndex) const;
79 CElement* getChild(uint32_t uiIndex);
80 const CElement* findChild(const string& strName) const;
81 CElement* findChild(const string& strName);
82 const CElement* findDescendant(CPathNavigator& pathNavigator) const;
83 CElement* findDescendant(CPathNavigator& pathNavigator);
84 bool isDescendantOf(const CElement* pCandidateAscendant) const;
85
86 // From IXmlSink
87 virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
88
89 // From IXmlSource
90 virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
91
92 // Content structure dump
93 void dumpContent(string& strContent, CErrorContext& errorContext, const uint32_t uiDepth = 0) const;
94
Patrick Benavoli2ecf9002011-08-31 11:23:24 +020095 // Element properties
96 virtual void showProperties(string& strResult) const;
97
98 // Conversion utilities
99 static string toString(uint32_t uiValue);
Guillaume Denneulin95331562012-09-27 15:13:10 +0200100 static string toString(uint64_t uiValue);
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200101 static string toString(int32_t iValue);
Patrick Benavoliee65e6d2011-11-20 18:52:24 +0100102 static string toString(double dValue);
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200103
Patrick Benavoli68a91282011-08-31 11:23:23 +0200104 // Checksum for integrity checks
105 uint8_t computeStructureChecksum() const;
106
107 // Class kind
108 virtual string getKind() const = 0;
109protected:
110 // Content dumping
111 virtual void logValue(string& strValue, CErrorContext& errorContext) const;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200112 // Utility to underline
113 static void appendTitle(string& strTo, const string& strTitle);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200114
115 // Hierarchy
116 CElement* getLastChild();
117 CElement* getParent();
118 CElement* findAscendantOfKind(const string& strKind);
119 CElement* getRoot();
120 const CElement* getRoot() const;
121private:
122 // Logging (done by root)
Kevin Rocardace81f82012-12-11 16:19:17 +0100123 virtual void doLog(bool bIsWarning, const string& strLog) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200124 virtual void nestLog() const;
125 virtual void unnestLog() const;
126 // Returns Name or Kind if no Name
127 string getPathName() const;
128 // Returns true if children dynamic creation is to be dealt with
129 virtual bool childrenAreDynamic() const;
130 // House keeping
131 void removeChildren();
132 // For logging
133 uint32_t getDepth() const;
134 // Fill XmlElement during XML composing
135 void setXmlNameAttribute(CXmlElement& xmlElement) const;
136
137 // Name
138 string _strName;
139
140 // Description
141 string _strDescription;
142
143 // Child iterators
144 typedef vector<CElement*>::iterator ChildArrayIterator;
145 typedef vector<CElement*>::reverse_iterator ChildArrayReverseIterator;
146 // Children
147 vector<CElement*> _childArray;
148 // Parent
149 CElement* _pParent;
150};