blob: 453f2442d72d46b1679f23f50b6f2a2d87622517 [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 "SelectionCriterion.h"
Patrick Benavolib71ccf72011-09-13 14:15:52 +020026#include "AutoLog.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020027
28#define base CElement
29
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +020030CSelectionCriterion::CSelectionCriterion(const string& strName, const CSelectionCriterionType* pType) : base(strName), _iState(0), _pType(pType), _uiNbModifications(0)
Patrick Benavoli68a91282011-08-31 11:23:23 +020031{
32}
33
34string CSelectionCriterion::getKind() const
35{
36 return "SelectionCriterion";
37}
38
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +020039bool CSelectionCriterion::hasBeenModified() const
40{
41 return _uiNbModifications != 0;
42}
43
44void CSelectionCriterion::resetModifiedStatus()
45{
46 _uiNbModifications = 0;
47}
48
Patrick Benavoli68a91282011-08-31 11:23:23 +020049/// From ISelectionCriterionInterface
50// State
Patrick Benavolib71ccf72011-09-13 14:15:52 +020051void CSelectionCriterion::setCriterionState(int iState)
Patrick Benavoli68a91282011-08-31 11:23:23 +020052{
53 // Check for a change
54 if (_iState != iState) {
55
56 _iState = iState;
Patrick Benavoli63499d42011-10-24 18:50:03 +020057
58 log("Selection criterion changed event: %s", getFormattedDescription(false).c_str());
Frédéric Boisnarddaaa63c2012-08-27 15:48:15 +020059
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 Benavoli68a91282011-08-31 11:23:23 +020069 }
70}
71
72int CSelectionCriterion::getCriterionState() const
73{
74 return _iState;
75}
76
77// Name
78string CSelectionCriterion::getCriterionName() const
79{
80 return getName();
81}
82
83// Type
84const ISelectionCriterionTypeInterface* CSelectionCriterion::getCriterionType() const
85{
86 return _pType;
87}
88
Patrick Benavoli68a91282011-08-31 11:23:23 +020089/// Match methods
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020090bool CSelectionCriterion::is(int iState) const
Patrick Benavoli68a91282011-08-31 11:23:23 +020091{
92 return _iState == iState;
93}
94
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020095bool CSelectionCriterion::isNot(int iState) const
96{
97 return _iState != iState;
98}
99
100bool CSelectionCriterion::includes(int iState) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200101{
102 return (_iState & iState) != 0;
103}
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200104
105bool CSelectionCriterion::excludes(int iState) const
106{
107 return (_iState & iState) == 0;
108}
109
110/// User request
111string 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}