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     ~CTypeElement() override;
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     void showProperties(std::string &strResult) const override;
62 
63     // From IXmlSink
64     bool fromXml(const CXmlElement &xmlElement,
65                  CXmlSerializingContext &serializingContext) override;
66 
67     // From IXmlSource
68     void toXml(CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) const override;
69 
70     // Scalar or Array?
71     bool isScalar() const;
72 
73     // Array Length
74     size_t getArrayLength() const;
75 
76     /**
77      * Converts size optimized integer input data (int8, int16, int32) to plain int
78      *
79      * @param[in] iSizeOptimizedData the data to convert
80      *
81      * @return the data with int type
82      */
83     virtual int toPlainInteger(int iSizeOptimizedData) const;
84 
85 protected:
86     // Object creation
87     virtual void populate(CElement *pElement) const;
88     /** @Returns the mapping associated to the current type and its predecessor
89      *
90      * The meaning of predecessor depends on the TypeElement type: e.g. for a
91      * component instance, the predecessor is the ComponentType; for a
92      * ComponentType, the predecessor is its base type.
93      *
94      * The predecessor's mapping comes first, then the current type's mapping.
95      *
96      * @param[in] predecessor A pointer to the predecessor or NULL.
97      */
98     std::string getFormattedMapping(const CTypeElement *predecessor) const;
99 
100 private:
101     CTypeElement(const CTypeElement &);
102     CTypeElement &operator=(const CTypeElement &);
103     // Actual instance creation
104     virtual CInstanceConfigurableElement *doInstantiate() const = 0;
105 
106     // Mapping data creation and access
107     CMappingData *getMappingData();
108 
109     // For Arrays. 0 means scalar
110     size_t _arrayLength{0};
111 
112     // Mapping info
113     CMappingData *_pMappingData{nullptr};
114 };
115