Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1 | /* <auto_header> |
| 2 | * <FILENAME> |
| 3 | * |
| 4 | * INTEL CONFIDENTIAL |
| 5 | * Copyright © 2011 Intel |
| 6 | * Corporation All Rights Reserved. |
| 7 | * |
| 8 | * The source code contained or described herein and all documents related to |
| 9 | * the source code ("Material") are owned by Intel Corporation or its suppliers |
| 10 | * or licensors. Title to the Material remains with Intel Corporation or its |
| 11 | * suppliers and licensors. The Material contains trade secrets and proprietary |
| 12 | * and confidential information of Intel or its suppliers and licensors. The |
| 13 | * Material is protected by worldwide copyright and trade secret laws and |
| 14 | * treaty provisions. No part of the Material may be used, copied, reproduced, |
| 15 | * modified, published, uploaded, posted, transmitted, distributed, or |
| 16 | * disclosed in any way without Intel’s prior express written permission. |
| 17 | * |
| 18 | * No license under any patent, copyright, trade secret or other intellectual |
| 19 | * property right is granted to or conferred upon you by disclosure or delivery |
| 20 | * of the Materials, either expressly, by implication, inducement, estoppel or |
| 21 | * otherwise. Any license under such intellectual property rights must be |
| 22 | * express and approved by Intel in writing. |
| 23 | * |
| 24 | * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com) |
| 25 | * CREATED: 2011-06-01 |
| 26 | * UPDATED: 2011-07-27 |
| 27 | * |
| 28 | * |
| 29 | * </auto_header> |
| 30 | */ |
| 31 | #include "SelectionCriterion.h" |
Patrick Benavoli | b71ccf7 | 2011-09-13 14:15:52 +0200 | [diff] [blame] | 32 | #include "AutoLog.h" |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 33 | |
| 34 | #define base CElement |
| 35 | |
Patrick Benavoli | b71ccf7 | 2011-09-13 14:15:52 +0200 | [diff] [blame] | 36 | CSelectionCriterion::CSelectionCriterion(const string& strName, const CSelectionCriterionType* pType) : base(strName), _iState(0), _pType(pType) |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 37 | { |
| 38 | } |
| 39 | |
| 40 | string CSelectionCriterion::getKind() const |
| 41 | { |
| 42 | return "SelectionCriterion"; |
| 43 | } |
| 44 | |
| 45 | /// From ISelectionCriterionInterface |
| 46 | // State |
Patrick Benavoli | b71ccf7 | 2011-09-13 14:15:52 +0200 | [diff] [blame] | 47 | void CSelectionCriterion::setCriterionState(int iState) |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 48 | { |
| 49 | // Check for a change |
| 50 | if (_iState != iState) { |
| 51 | |
Patrick Benavoli | b71ccf7 | 2011-09-13 14:15:52 +0200 | [diff] [blame] | 52 | CAutoLog autoLog(this, "Selection criterion changed event: " + getFormattedDescription(false)); |
| 53 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 54 | _iState = iState; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
| 58 | int CSelectionCriterion::getCriterionState() const |
| 59 | { |
| 60 | return _iState; |
| 61 | } |
| 62 | |
| 63 | // Name |
| 64 | string CSelectionCriterion::getCriterionName() const |
| 65 | { |
| 66 | return getName(); |
| 67 | } |
| 68 | |
| 69 | // Type |
| 70 | const ISelectionCriterionTypeInterface* CSelectionCriterion::getCriterionType() const |
| 71 | { |
| 72 | return _pType; |
| 73 | } |
| 74 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 75 | /// Match methods |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 76 | bool CSelectionCriterion::is(int iState) const |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 77 | { |
| 78 | return _iState == iState; |
| 79 | } |
| 80 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 81 | bool CSelectionCriterion::isNot(int iState) const |
| 82 | { |
| 83 | return _iState != iState; |
| 84 | } |
| 85 | |
| 86 | bool CSelectionCriterion::includes(int iState) const |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 87 | { |
| 88 | return (_iState & iState) != 0; |
| 89 | } |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 90 | |
| 91 | bool CSelectionCriterion::excludes(int iState) const |
| 92 | { |
| 93 | return (_iState & iState) == 0; |
| 94 | } |
| 95 | |
| 96 | /// User request |
| 97 | string CSelectionCriterion::getFormattedDescription(bool bWithTypeInfo) const |
| 98 | { |
| 99 | string strFormattedDescription; |
| 100 | |
| 101 | if (bWithTypeInfo) { |
| 102 | |
| 103 | // Display type info |
| 104 | appendTitle(strFormattedDescription, getName() + ":"); |
| 105 | |
| 106 | // States |
| 107 | strFormattedDescription += "Possible states "; |
| 108 | |
| 109 | // Type Kind |
| 110 | strFormattedDescription += "("; |
| 111 | strFormattedDescription += _pType->isTypeInclusive() ? "Inclusive" : "Exclusive"; |
| 112 | strFormattedDescription += "): "; |
| 113 | |
| 114 | // States |
| 115 | strFormattedDescription += _pType->listPossibleValues() + "\n"; |
| 116 | |
| 117 | // Current State |
| 118 | strFormattedDescription += "Current state"; |
| 119 | } else { |
| 120 | // Name only |
| 121 | strFormattedDescription = getName(); |
| 122 | } |
| 123 | |
| 124 | // Current State |
| 125 | strFormattedDescription += " = " + _pType->getFormattedState(_iState); |
| 126 | |
| 127 | return strFormattedDescription; |
| 128 | } |