blob: b381898a932c8c5c7bd3195e7961fe212e1bff80 [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>
Kevin Rocard36299362013-02-04 14:57:47 +010030#include <list>
Patrick Benavoli68a91282011-08-31 11:23:23 +020031#include "XmlSink.h"
32#include "XmlSource.h"
33
34#include "PathNavigator.h"
35
36using namespace std;
37
38class CXmlElementSerializingContext;
39class CErrorContext;
40
41class CElement : public IXmlSink, public IXmlSource
42{
43 friend class CAutoLog;
44public:
45 CElement(const string& strName = "");
46 virtual ~CElement();
47
48 // Logging
Kevin Rocardace81f82012-12-11 16:19:17 +010049 void log_info(const string& strMessage, ...) const;
50 void log_warning(const string& strMessage, ...) const;
Kevin Rocard36299362013-02-04 14:57:47 +010051 void log_table(bool bIsWarning, const list<string> lstrMessage) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +020052
53 // Description
54 void setDescription(const string& strDescription);
55 const string& getDescription() const;
56
57 // Name / Path
58 const string& getName() const;
Patrick Benavoli95ac0342011-11-07 20:32:51 +010059 void setName(const string& strName);
Patrick Benavoli68a91282011-08-31 11:23:23 +020060 bool rename(const string& strName, string& strError);
61 string getPath() const;
62 string getQualifiedPath() const;
63
64 // Creation / build
65 virtual bool init(string& strError);
66 virtual void clean();
67
68 // Children management
69 void addChild(CElement* pChild);
70 bool removeChild(CElement* pChild);
71 void listChildren(string& strChildList) const;
72 string listQualifiedPaths(bool bDive, uint32_t uiLevel = 0) const;
73 void listChildrenPaths(string& strChildPathList) const;
74
75 // Hierarchy query
76 uint32_t getNbChildren() const;
77 CElement* findChildOfKind(const string& strKind);
78 const CElement* findChildOfKind(const string& strKind) const;
79 const CElement* getParent() const;
80 const CElement* getChild(uint32_t uiIndex) const;
81 CElement* getChild(uint32_t uiIndex);
82 const CElement* findChild(const string& strName) const;
83 CElement* findChild(const string& strName);
84 const CElement* findDescendant(CPathNavigator& pathNavigator) const;
85 CElement* findDescendant(CPathNavigator& pathNavigator);
86 bool isDescendantOf(const CElement* pCandidateAscendant) const;
87
88 // From IXmlSink
89 virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
90
91 // From IXmlSource
92 virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
93
94 // Content structure dump
95 void dumpContent(string& strContent, CErrorContext& errorContext, const uint32_t uiDepth = 0) const;
96
Patrick Benavoli2ecf9002011-08-31 11:23:24 +020097 // Element properties
98 virtual void showProperties(string& strResult) const;
99
100 // Conversion utilities
101 static string toString(uint32_t uiValue);
Guillaume Denneulin95331562012-09-27 15:13:10 +0200102 static string toString(uint64_t uiValue);
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200103 static string toString(int32_t iValue);
Patrick Benavoliee65e6d2011-11-20 18:52:24 +0100104 static string toString(double dValue);
Patrick Benavoli2ecf9002011-08-31 11:23:24 +0200105
Patrick Benavoli68a91282011-08-31 11:23:23 +0200106 // Checksum for integrity checks
107 uint8_t computeStructureChecksum() const;
108
109 // Class kind
110 virtual string getKind() const = 0;
111protected:
112 // Content dumping
113 virtual void logValue(string& strValue, CErrorContext& errorContext) const;
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200114 // Utility to underline
115 static void appendTitle(string& strTo, const string& strTitle);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200116
117 // Hierarchy
118 CElement* getLastChild();
119 CElement* getParent();
120 CElement* findAscendantOfKind(const string& strKind);
121 CElement* getRoot();
122 const CElement* getRoot() const;
123private:
124 // Logging (done by root)
Kevin Rocardace81f82012-12-11 16:19:17 +0100125 virtual void doLog(bool bIsWarning, const string& strLog) const;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200126 virtual void nestLog() const;
127 virtual void unnestLog() const;
128 // Returns Name or Kind if no Name
129 string getPathName() const;
130 // Returns true if children dynamic creation is to be dealt with
131 virtual bool childrenAreDynamic() const;
132 // House keeping
133 void removeChildren();
134 // For logging
135 uint32_t getDepth() const;
136 // Fill XmlElement during XML composing
137 void setXmlNameAttribute(CXmlElement& xmlElement) const;
138
139 // Name
140 string _strName;
141
142 // Description
143 string _strDescription;
144
145 // Child iterators
146 typedef vector<CElement*>::iterator ChildArrayIterator;
147 typedef vector<CElement*>::reverse_iterator ChildArrayReverseIterator;
148 // Children
149 vector<CElement*> _childArray;
150 // Parent
151 CElement* _pParent;
152};