Kevin Rocard | 93250d1 | 2012-07-19 17:48:30 +0200 | [diff] [blame] | 1 | /* |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 2 | * 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 Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 22 | * CREATED: 2011-06-01 |
| 23 | * UPDATED: 2011-07-27 |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 24 | */ |
| 25 | #pragma once |
| 26 | |
| 27 | #include <string> |
| 28 | #include <vector> |
| 29 | #include <stdint.h> |
Kevin Rocard | 3629936 | 2013-02-04 14:57:47 +0100 | [diff] [blame] | 30 | #include <list> |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 31 | #include "XmlSink.h" |
| 32 | #include "XmlSource.h" |
| 33 | |
| 34 | #include "PathNavigator.h" |
| 35 | |
| 36 | using namespace std; |
| 37 | |
| 38 | class CXmlElementSerializingContext; |
| 39 | class CErrorContext; |
| 40 | |
| 41 | class CElement : public IXmlSink, public IXmlSource |
| 42 | { |
| 43 | friend class CAutoLog; |
| 44 | public: |
| 45 | CElement(const string& strName = ""); |
| 46 | virtual ~CElement(); |
| 47 | |
| 48 | // Logging |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 49 | void log_info(const string& strMessage, ...) const; |
| 50 | void log_warning(const string& strMessage, ...) const; |
Kevin Rocard | 3629936 | 2013-02-04 14:57:47 +0100 | [diff] [blame] | 51 | void log_table(bool bIsWarning, const list<string> lstrMessage) const; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 52 | |
| 53 | // Description |
| 54 | void setDescription(const string& strDescription); |
| 55 | const string& getDescription() const; |
| 56 | |
| 57 | // Name / Path |
| 58 | const string& getName() const; |
Patrick Benavoli | 95ac034 | 2011-11-07 20:32:51 +0100 | [diff] [blame] | 59 | void setName(const string& strName); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 60 | 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 Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 97 | // Element properties |
| 98 | virtual void showProperties(string& strResult) const; |
| 99 | |
| 100 | // Conversion utilities |
| 101 | static string toString(uint32_t uiValue); |
Guillaume Denneulin | 9533156 | 2012-09-27 15:13:10 +0200 | [diff] [blame] | 102 | static string toString(uint64_t uiValue); |
Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 103 | static string toString(int32_t iValue); |
Patrick Benavoli | ee65e6d | 2011-11-20 18:52:24 +0100 | [diff] [blame] | 104 | static string toString(double dValue); |
Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 105 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 106 | // Checksum for integrity checks |
| 107 | uint8_t computeStructureChecksum() const; |
| 108 | |
| 109 | // Class kind |
| 110 | virtual string getKind() const = 0; |
| 111 | protected: |
| 112 | // Content dumping |
| 113 | virtual void logValue(string& strValue, CErrorContext& errorContext) const; |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 114 | // Utility to underline |
| 115 | static void appendTitle(string& strTo, const string& strTitle); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 116 | |
| 117 | // Hierarchy |
| 118 | CElement* getLastChild(); |
| 119 | CElement* getParent(); |
| 120 | CElement* findAscendantOfKind(const string& strKind); |
| 121 | CElement* getRoot(); |
| 122 | const CElement* getRoot() const; |
Guillaume Denneulin | 3ba083e | 2014-01-31 15:09:42 +0100 | [diff] [blame^] | 123 | |
| 124 | /** |
| 125 | * Creates a child CElement from a child XML Element |
| 126 | * |
| 127 | * @param[in] childElement the XML element to create CElement from |
| 128 | * @param[in] elementSerializingContext the serializing context |
| 129 | * |
| 130 | * @return child a pointer on the CElement object that has been added to the tree |
| 131 | */ |
| 132 | CElement* createChild(const CXmlElement& childElement, |
| 133 | CXmlSerializingContext& elementSerializingContext); |
| 134 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 135 | private: |
| 136 | // Logging (done by root) |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame] | 137 | virtual void doLog(bool bIsWarning, const string& strLog) const; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 138 | virtual void nestLog() const; |
| 139 | virtual void unnestLog() const; |
| 140 | // Returns Name or Kind if no Name |
| 141 | string getPathName() const; |
| 142 | // Returns true if children dynamic creation is to be dealt with |
| 143 | virtual bool childrenAreDynamic() const; |
| 144 | // House keeping |
| 145 | void removeChildren(); |
| 146 | // For logging |
| 147 | uint32_t getDepth() const; |
| 148 | // Fill XmlElement during XML composing |
| 149 | void setXmlNameAttribute(CXmlElement& xmlElement) const; |
| 150 | |
| 151 | // Name |
| 152 | string _strName; |
| 153 | |
| 154 | // Description |
| 155 | string _strDescription; |
| 156 | |
| 157 | // Child iterators |
| 158 | typedef vector<CElement*>::iterator ChildArrayIterator; |
| 159 | typedef vector<CElement*>::reverse_iterator ChildArrayReverseIterator; |
| 160 | // Children |
| 161 | vector<CElement*> _childArray; |
| 162 | // Parent |
| 163 | CElement* _pParent; |
| 164 | }; |