blob: d3e561b8046ac7844f8037abb28ba0cdf045e634 [file] [log] [blame]
Patrick Benavoli68a91282011-08-31 11:23:23 +02001/* <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 Benavolib71ccf72011-09-13 14:15:52 +020032#include "AutoLog.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020033
34#define base CElement
35
Patrick Benavolib71ccf72011-09-13 14:15:52 +020036CSelectionCriterion::CSelectionCriterion(const string& strName, const CSelectionCriterionType* pType) : base(strName), _iState(0), _pType(pType)
Patrick Benavoli68a91282011-08-31 11:23:23 +020037{
38}
39
40string CSelectionCriterion::getKind() const
41{
42 return "SelectionCriterion";
43}
44
45/// From ISelectionCriterionInterface
46// State
Patrick Benavolib71ccf72011-09-13 14:15:52 +020047void CSelectionCriterion::setCriterionState(int iState)
Patrick Benavoli68a91282011-08-31 11:23:23 +020048{
49 // Check for a change
50 if (_iState != iState) {
51
Patrick Benavolib71ccf72011-09-13 14:15:52 +020052 CAutoLog autoLog(this, "Selection criterion changed event: " + getFormattedDescription(false));
53
Patrick Benavoli68a91282011-08-31 11:23:23 +020054 _iState = iState;
Patrick Benavoli68a91282011-08-31 11:23:23 +020055 }
56}
57
58int CSelectionCriterion::getCriterionState() const
59{
60 return _iState;
61}
62
63// Name
64string CSelectionCriterion::getCriterionName() const
65{
66 return getName();
67}
68
69// Type
70const ISelectionCriterionTypeInterface* CSelectionCriterion::getCriterionType() const
71{
72 return _pType;
73}
74
Patrick Benavoli68a91282011-08-31 11:23:23 +020075/// Match methods
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020076bool CSelectionCriterion::is(int iState) const
Patrick Benavoli68a91282011-08-31 11:23:23 +020077{
78 return _iState == iState;
79}
80
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020081bool CSelectionCriterion::isNot(int iState) const
82{
83 return _iState != iState;
84}
85
86bool CSelectionCriterion::includes(int iState) const
Patrick Benavoli68a91282011-08-31 11:23:23 +020087{
88 return (_iState & iState) != 0;
89}
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020090
91bool CSelectionCriterion::excludes(int iState) const
92{
93 return (_iState & iState) == 0;
94}
95
96/// User request
97string 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}