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 "SelectionCriterion.h" |
Patrick Benavoli | b71ccf7 | 2011-09-13 14:15:52 +0200 | [diff] [blame] | 26 | #include "AutoLog.h" |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 27 | |
| 28 | #define base CElement |
| 29 | |
Frédéric Boisnard | daaa63c | 2012-08-27 15:48:15 +0200 | [diff] [blame^] | 30 | CSelectionCriterion::CSelectionCriterion(const string& strName, const CSelectionCriterionType* pType) : base(strName), _iState(0), _pType(pType), _uiNbModifications(0) |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 31 | { |
| 32 | } |
| 33 | |
| 34 | string CSelectionCriterion::getKind() const |
| 35 | { |
| 36 | return "SelectionCriterion"; |
| 37 | } |
| 38 | |
Frédéric Boisnard | daaa63c | 2012-08-27 15:48:15 +0200 | [diff] [blame^] | 39 | bool CSelectionCriterion::hasBeenModified() const |
| 40 | { |
| 41 | return _uiNbModifications != 0; |
| 42 | } |
| 43 | |
| 44 | void CSelectionCriterion::resetModifiedStatus() |
| 45 | { |
| 46 | _uiNbModifications = 0; |
| 47 | } |
| 48 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 49 | /// From ISelectionCriterionInterface |
| 50 | // State |
Patrick Benavoli | b71ccf7 | 2011-09-13 14:15:52 +0200 | [diff] [blame] | 51 | void CSelectionCriterion::setCriterionState(int iState) |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 52 | { |
| 53 | // Check for a change |
| 54 | if (_iState != iState) { |
| 55 | |
| 56 | _iState = iState; |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 57 | |
| 58 | log("Selection criterion changed event: %s", getFormattedDescription(false).c_str()); |
Frédéric Boisnard | daaa63c | 2012-08-27 15:48:15 +0200 | [diff] [blame^] | 59 | |
| 60 | // Check if the previous criterion value has been taken into account (i.e. at least one Configuration was applied |
| 61 | // since the last criterion change) |
| 62 | if (_uiNbModifications > 0) { |
| 63 | |
| 64 | log("Warning: Selection criterion \"%s\" has been modified %d time(s) without any configuration application", getName().c_str(), _uiNbModifications); |
| 65 | } |
| 66 | |
| 67 | // Track the number of modifications for this criterion |
| 68 | _uiNbModifications++; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | int CSelectionCriterion::getCriterionState() const |
| 73 | { |
| 74 | return _iState; |
| 75 | } |
| 76 | |
| 77 | // Name |
| 78 | string CSelectionCriterion::getCriterionName() const |
| 79 | { |
| 80 | return getName(); |
| 81 | } |
| 82 | |
| 83 | // Type |
| 84 | const ISelectionCriterionTypeInterface* CSelectionCriterion::getCriterionType() const |
| 85 | { |
| 86 | return _pType; |
| 87 | } |
| 88 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 89 | /// Match methods |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 90 | bool CSelectionCriterion::is(int iState) const |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 91 | { |
| 92 | return _iState == iState; |
| 93 | } |
| 94 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 95 | bool CSelectionCriterion::isNot(int iState) const |
| 96 | { |
| 97 | return _iState != iState; |
| 98 | } |
| 99 | |
| 100 | bool CSelectionCriterion::includes(int iState) const |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 101 | { |
| 102 | return (_iState & iState) != 0; |
| 103 | } |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 104 | |
| 105 | bool CSelectionCriterion::excludes(int iState) const |
| 106 | { |
| 107 | return (_iState & iState) == 0; |
| 108 | } |
| 109 | |
| 110 | /// User request |
| 111 | string CSelectionCriterion::getFormattedDescription(bool bWithTypeInfo) const |
| 112 | { |
| 113 | string strFormattedDescription; |
| 114 | |
| 115 | if (bWithTypeInfo) { |
| 116 | |
| 117 | // Display type info |
| 118 | appendTitle(strFormattedDescription, getName() + ":"); |
| 119 | |
| 120 | // States |
| 121 | strFormattedDescription += "Possible states "; |
| 122 | |
| 123 | // Type Kind |
| 124 | strFormattedDescription += "("; |
| 125 | strFormattedDescription += _pType->isTypeInclusive() ? "Inclusive" : "Exclusive"; |
| 126 | strFormattedDescription += "): "; |
| 127 | |
| 128 | // States |
| 129 | strFormattedDescription += _pType->listPossibleValues() + "\n"; |
| 130 | |
| 131 | // Current State |
| 132 | strFormattedDescription += "Current state"; |
| 133 | } else { |
| 134 | // Name only |
| 135 | strFormattedDescription = getName(); |
| 136 | } |
| 137 | |
| 138 | // Current State |
| 139 | strFormattedDescription += " = " + _pType->getFormattedState(_iState); |
| 140 | |
| 141 | return strFormattedDescription; |
| 142 | } |