1 /* 2 * Copyright (c) 2011-2015, Intel Corporation 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation and/or 13 * other materials provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors 16 * may be used to endorse or promote products derived from this software without 17 * specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 #pragma once 31 32 #include "parameter_export.h" 33 34 #include "Element.h" 35 #include <string> 36 37 class CMappingData; 38 class CInstanceConfigurableElement; 39 40 class PARAMETER_EXPORT CTypeElement : public CElement 41 { 42 public: 43 CTypeElement(const std::string &strName = ""); 44 virtual ~CTypeElement(); 45 46 // Instantiation 47 CInstanceConfigurableElement *instantiate() const; 48 49 // Mapping info 50 virtual bool getMappingData(const std::string &strKey, const std::string *&pStrValue) const; 51 virtual bool hasMappingData() const; 52 53 /** 54 * Returns the mapping associated to the current TypeElement instance 55 * 56 * @return A std::string containing the mapping as a comma separated key value pairs 57 */ 58 virtual std::string getFormattedMapping() const; 59 60 // Element properties 61 virtual void showProperties(std::string &strResult) const; 62 63 // From IXmlSink 64 virtual bool fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext); 65 66 // From IXmlSource 67 virtual void toXml(CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) const; 68 69 // Scalar or Array? 70 bool isScalar() const; 71 72 // Array Length 73 size_t getArrayLength() const; 74 75 /** 76 * Converts size optimized integer input data (int8, int16, int32) to plain int 77 * 78 * @param[in] iSizeOptimizedData the data to convert 79 * 80 * @return the data with int type 81 */ 82 virtual int toPlainInteger(int iSizeOptimizedData) const; 83 84 protected: 85 // Object creation 86 virtual void populate(CElement *pElement) const; 87 /** @Returns the mapping associated to the current type and its predecessor 88 * 89 * The meaning of predecessor depends on the TypeElement type: e.g. for a 90 * component instance, the predecessor is the ComponentType; for a 91 * ComponentType, the predecessor is its base type. 92 * 93 * The predecessor's mapping comes first, then the current type's mapping. 94 * 95 * @param[in] predecessor A pointer to the predecessor or NULL. 96 */ 97 std::string getFormattedMapping(const CTypeElement *predecessor) const; 98 99 private: 100 CTypeElement(const CTypeElement &); 101 CTypeElement &operator=(const CTypeElement &); 102 // Actual instance creation 103 virtual CInstanceConfigurableElement *doInstantiate() const = 0; 104 105 // Mapping data creation and access 106 CMappingData *getMappingData(); 107 108 // For Arrays. 0 means scalar 109 size_t _arrayLength{0}; 110 111 // Mapping info 112 CMappingData *_pMappingData{nullptr}; 113 }; 114