blob: 43d6a6b5c681ca10a999706699a3c212cdb5131d [file] [log] [blame]
Kevin Rocard93250d12012-07-19 17:48:30 +02001/*
Patrick Benavoli68a91282011-08-31 11:23:23 +02002 * 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 Benavoli68a91282011-08-31 11:23:23 +020022 * CREATED: 2011-06-01
23 * UPDATED: 2011-07-27
Patrick Benavoli68a91282011-08-31 11:23:23 +020024 */
25#include "MappingContext.h"
26#include <string.h>
27#include <stdlib.h>
28
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020029CMappingContext::CMappingContext(uint32_t uiNbItemTypes) : _pstItemArray(new CMappingContext::SItem[uiNbItemTypes]), _uiNbItemTypes(uiNbItemTypes)
Patrick Benavoli68a91282011-08-31 11:23:23 +020030{
31 // Clear items
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020032 memset(_pstItemArray, 0, sizeof(*_pstItemArray) * uiNbItemTypes);
Patrick Benavoli68a91282011-08-31 11:23:23 +020033}
34
35CMappingContext::~CMappingContext()
36{
37 delete [] _pstItemArray;
38}
39
40// Copy constructor
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020041CMappingContext::CMappingContext(const CMappingContext& from) : _pstItemArray(new CMappingContext::SItem[from._uiNbItemTypes]), _uiNbItemTypes(from._uiNbItemTypes)
Patrick Benavoli68a91282011-08-31 11:23:23 +020042{
43 // Copy content items
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020044 memcpy(_pstItemArray, from._pstItemArray, sizeof(*_pstItemArray) * _uiNbItemTypes);
Patrick Benavoli68a91282011-08-31 11:23:23 +020045}
46
47// Affectation
48const CMappingContext& CMappingContext::operator=(const CMappingContext& right)
49{
50 if (&right != this) {
51
52 // Size
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020053 _uiNbItemTypes = right._uiNbItemTypes;
Patrick Benavoli68a91282011-08-31 11:23:23 +020054
55 // Content
56 // Delete previous array
57 delete [] _pstItemArray;
58
59 // Reallocate it
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020060 _pstItemArray = new CMappingContext::SItem[_uiNbItemTypes];
Patrick Benavoli68a91282011-08-31 11:23:23 +020061
62 // Copy content items
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020063 memcpy(_pstItemArray, right._pstItemArray, sizeof(*_pstItemArray) * _uiNbItemTypes);
Patrick Benavoli68a91282011-08-31 11:23:23 +020064 }
65 return *this;
66}
67
68// Item access
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020069bool CMappingContext::setItem(uint32_t uiItemType, const string* pStrItem)
Patrick Benavoli68a91282011-08-31 11:23:23 +020070{
71 // Do some checks
72 if (_pstItemArray[uiItemType].bSet) {
73
74 // Already set!
75 return false;
76 }
77 // Get item value
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020078 _pstItemArray[uiItemType].strItem = pStrItem;
Patrick Benavoli68a91282011-08-31 11:23:23 +020079
80 // Now is set
81 _pstItemArray[uiItemType].bSet = true;
82
83 return true;
84}
85
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020086const string& CMappingContext::getItem(uint32_t uiItemType) const
Patrick Benavoli68a91282011-08-31 11:23:23 +020087{
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020088 return *_pstItemArray[uiItemType].strItem;
89}
90
91uint32_t CMappingContext::getItemAsInteger(uint32_t uiItemType) const
92{
93 if (!_pstItemArray[uiItemType].strItem) {
94
95 return 0;
96 }
97
98 return strtoul(_pstItemArray[uiItemType].strItem->c_str(), NULL, 0);
Patrick Benavoli68a91282011-08-31 11:23:23 +020099}
100
101bool CMappingContext::iSet(uint32_t uiItemType) const
102{
103 return _pstItemArray[uiItemType].bSet;
104}