| 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 | #include "MappingContext.h" |
| 26 | #include <string.h> |
| 27 | #include <stdlib.h> |
| 28 | |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 29 | CMappingContext::CMappingContext(uint32_t uiNbItemTypes) : _pstItemArray(new CMappingContext::SItem[uiNbItemTypes]), _uiNbItemTypes(uiNbItemTypes) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 30 | { |
| 31 | // Clear items |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 32 | memset(_pstItemArray, 0, sizeof(*_pstItemArray) * uiNbItemTypes); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | CMappingContext::~CMappingContext() |
| 36 | { |
| 37 | delete [] _pstItemArray; |
| 38 | } |
| 39 | |
| 40 | // Copy constructor |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 41 | CMappingContext::CMappingContext(const CMappingContext& from) : _pstItemArray(new CMappingContext::SItem[from._uiNbItemTypes]), _uiNbItemTypes(from._uiNbItemTypes) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 42 | { |
| 43 | // Copy content items |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 44 | memcpy(_pstItemArray, from._pstItemArray, sizeof(*_pstItemArray) * _uiNbItemTypes); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | // Affectation |
| 48 | const CMappingContext& CMappingContext::operator=(const CMappingContext& right) |
| 49 | { |
| 50 | if (&right != this) { |
| 51 | |
| 52 | // Size |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 53 | _uiNbItemTypes = right._uiNbItemTypes; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 54 | |
| 55 | // Content |
| 56 | // Delete previous array |
| 57 | delete [] _pstItemArray; |
| 58 | |
| 59 | // Reallocate it |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 60 | _pstItemArray = new CMappingContext::SItem[_uiNbItemTypes]; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 61 | |
| 62 | // Copy content items |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 63 | memcpy(_pstItemArray, right._pstItemArray, sizeof(*_pstItemArray) * _uiNbItemTypes); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 64 | } |
| 65 | return *this; |
| 66 | } |
| 67 | |
| 68 | // Item access |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 69 | bool CMappingContext::setItem(uint32_t uiItemType, const string* pStrItem) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 70 | { |
| 71 | // Do some checks |
| 72 | if (_pstItemArray[uiItemType].bSet) { |
| 73 | |
| 74 | // Already set! |
| 75 | return false; |
| 76 | } |
| 77 | // Get item value |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 78 | _pstItemArray[uiItemType].strItem = pStrItem; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 79 | |
| 80 | // Now is set |
| 81 | _pstItemArray[uiItemType].bSet = true; |
| 82 | |
| 83 | return true; |
| 84 | } |
| 85 | |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 86 | const string& CMappingContext::getItem(uint32_t uiItemType) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 87 | { |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 88 | return *_pstItemArray[uiItemType].strItem; |
| 89 | } |
| 90 | |
| 91 | uint32_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 Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | bool CMappingContext::iSet(uint32_t uiItemType) const |
| 102 | { |
| 103 | return _pstItemArray[uiItemType].bSet; |
| 104 | } |