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> |
| 30 | #include "XmlSink.h" |
| 31 | #include "XmlSource.h" |
| 32 | |
| 33 | #include "PathNavigator.h" |
| 34 | |
| 35 | using namespace std; |
| 36 | |
| 37 | class CXmlElementSerializingContext; |
| 38 | class CErrorContext; |
| 39 | |
| 40 | class CElement : public IXmlSink, public IXmlSource |
| 41 | { |
| 42 | friend class CAutoLog; |
| 43 | public: |
| 44 | CElement(const string& strName = ""); |
| 45 | virtual ~CElement(); |
| 46 | |
| 47 | // Logging |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame^] | 48 | void log_info(const string& strMessage, ...) const; |
| 49 | void log_warning(const string& strMessage, ...) const; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 50 | |
| 51 | // Description |
| 52 | void setDescription(const string& strDescription); |
| 53 | const string& getDescription() const; |
| 54 | |
| 55 | // Name / Path |
| 56 | const string& getName() const; |
Patrick Benavoli | 95ac034 | 2011-11-07 20:32:51 +0100 | [diff] [blame] | 57 | void setName(const string& strName); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 58 | 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 Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 95 | // Element properties |
| 96 | virtual void showProperties(string& strResult) const; |
| 97 | |
| 98 | // Conversion utilities |
| 99 | static string toString(uint32_t uiValue); |
Guillaume Denneulin | 9533156 | 2012-09-27 15:13:10 +0200 | [diff] [blame] | 100 | static string toString(uint64_t uiValue); |
Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 101 | static string toString(int32_t iValue); |
Patrick Benavoli | ee65e6d | 2011-11-20 18:52:24 +0100 | [diff] [blame] | 102 | static string toString(double dValue); |
Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 103 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 104 | // Checksum for integrity checks |
| 105 | uint8_t computeStructureChecksum() const; |
| 106 | |
| 107 | // Class kind |
| 108 | virtual string getKind() const = 0; |
| 109 | protected: |
| 110 | // Content dumping |
| 111 | virtual void logValue(string& strValue, CErrorContext& errorContext) const; |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 112 | // Utility to underline |
| 113 | static void appendTitle(string& strTo, const string& strTitle); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 114 | |
| 115 | // Hierarchy |
| 116 | CElement* getLastChild(); |
| 117 | CElement* getParent(); |
| 118 | CElement* findAscendantOfKind(const string& strKind); |
| 119 | CElement* getRoot(); |
| 120 | const CElement* getRoot() const; |
| 121 | private: |
| 122 | // Logging (done by root) |
Kevin Rocard | ace81f8 | 2012-12-11 16:19:17 +0100 | [diff] [blame^] | 123 | virtual void doLog(bool bIsWarning, const string& strLog) const; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 124 | 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 | }; |