blob: 99e7d10ec00761887b1e5fff4973a9a024d9f73c [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;
62 bool rename(const string& strName, string& strError);
63 string getPath() const;
64 string getQualifiedPath() const;
65
66 // Creation / build
67 virtual bool init(string& strError);
68 virtual void clean();
69
70 // Children management
71 void addChild(CElement* pChild);
72 bool removeChild(CElement* pChild);
73 void listChildren(string& strChildList) const;
74 string listQualifiedPaths(bool bDive, uint32_t uiLevel = 0) const;
75 void listChildrenPaths(string& strChildPathList) const;
76
77 // Hierarchy query
78 uint32_t getNbChildren() const;
79 CElement* findChildOfKind(const string& strKind);
80 const CElement* findChildOfKind(const string& strKind) const;
81 const CElement* getParent() const;
82 const CElement* getChild(uint32_t uiIndex) const;
83 CElement* getChild(uint32_t uiIndex);
84 const CElement* findChild(const string& strName) const;
85 CElement* findChild(const string& strName);
86 const CElement* findDescendant(CPathNavigator& pathNavigator) const;
87 CElement* findDescendant(CPathNavigator& pathNavigator);
88 bool isDescendantOf(const CElement* pCandidateAscendant) const;
89
90 // From IXmlSink
91 virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
92
93 // From IXmlSource
94 virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
95
96 // Content structure dump
97 void dumpContent(string& strContent, CErrorContext& errorContext, const uint32_t uiDepth = 0) const;
98
Patrick Benavoli2ecf9002011-08-31 11:23:24 +020099 // Element properties
100 virtual void showProperties(string& strResult) const;
101
102 // Conversion utilities
103 static string toString(uint32_t uiValue);
104 static string toString(int32_t iValue);
105
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;
114 // Name setting
115 void setName(const string& strName);
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};