summaryrefslogtreecommitdiffstats
path: root/src/include/usr/targeting/common/predicates/predicateattrval.H
blob: 7d62ea5ea0b69684c7359a8866bf874ddbe78b24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/include/usr/targeting/common/predicates/predicateattrval.H $ */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2013                   */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

#ifndef __TARGETING_COMMON_PREDICATEATTRVAL_H
#define __TARGETING_COMMON_PREDICATEATTRVAL_H

/**
 *  @file targeting/common/predicates/predicateattrval.H
 *
 *  @brief Interface and implementation for a predicate which filters a target
 *      based on whether it possesses a given attribute, and if so, the 
 *      attribute's value
 */

//******************************************************************************
// Includes
//******************************************************************************

// STD

// Other Host Boot Components

// Targeting Component
#include <targeting/common/target.H>
#include <targeting/common/attributes.H>
#include <targeting/common/predicates/predicatebase.H>

//******************************************************************************
// Interface and implementation
//******************************************************************************

namespace TARGETING
{

#define TARG_NAMESPACE "TARGETING::"
#define TARG_CLASS "PredicateAttrVal::"

class Target;

/**
 *  @brief Templated predicate class which filters a target based on whether it
 *      possesses a given attribute, and if so, the attribute's value
 */
template<const ATTRIBUTE_ID A>
class PredicateAttrVal : public PredicateBase
{
    public:

        /**
         *  @brief Constructor which configures the predicate to filter targets
         *      based on the existence of the attribute type given by the "A" 
         *      template parameter, and the input criteria
         *
         *  @param[in] i_value
         *      Assuming the target being filtered has the attribute given by
         *      the "A" template parameter, the value of that attribute
         *      that will cause the predicate to register a match.  If the
         *      i_invertSearch parameter is the non-default value of true, 
         *      the predicate registers a match when the value of the 
         *      attribute != i_value
         *  @param[in] i_invertSearch
         *      Assuming the attribute is present, this determines what check 
         *      needs to be performed on i_value.
         *      If false (default), the predicate registers a match when the 
         *      attribute's value is i_value; If false, the predicate registers
         *      a match when the attribute's value is != i_value
         */
        PredicateAttrVal(
            const typename AttributeTraits<A>::Type& i_value,
            const bool i_invertSearch = false)
            : iv_value(i_value), iv_invertSearch(i_invertSearch)
        {
        }

        /**
         *  @brief Destroys the attribute value predicate
         */
        virtual ~PredicateAttrVal() 
        { 
        }

        /**
         *  @brief Returns whether target has an attribute, given by template
         *      parameter "A", whose value matches the filter's configured
         *      criteria
         * 
         *  @par Detailed Description:
         *      Returns whether target has an attribute, given by template
         *      parameter "A", whose value matches the filter's configured
         *      value.  Note that the target must have the "A" attribute,
         *      otherwise the predicate will always return false.
         *      Assuming the target has the "A" attribute, if the attribute's
         *      value matches and the search is not inverted, the predicate
         *      returns true.  If the attribute's value does not match but the
         *      search is inverted, the predicate also returns true.  
         *      Otherwise, the predicate returns false.  See
         *      PredicateBase class for parameter/return description.
         *
         *  @param[in] i_pTarget
         *      Target handle pointing to the target to compare to.  Must 
         *      not be NULL.  
         *
         *  @return bool indicating whether the target matches or not
         */
        virtual bool operator()(
            const Target* i_pTarget) const
        {
            typename AttributeTraits<A>::Type actual; // not set intentionally
            bool l_match = i_pTarget->tryGetAttr<A>(actual);
            if(iv_invertSearch == true)
            {
                l_match = (l_match && !(iv_value == actual));
            }
            else
            {
                l_match = (l_match && (iv_value == actual));
            }
            return l_match;
        }

    private:
 
        /**
         *  @brief Value of attribute to compare for each target filter is
         *      applied to 
         */
        typename AttributeTraits<A>::Type iv_value;

        // Whether to look for attribute whose value matches iv_value (false) or
        // an attribute whose value does not match iv_value (true) for target 
        // being filtered
        bool iv_invertSearch;
 
        /**
         *  @brief Disable copy/assignment operators
         */
        TARG_DISABLE_COPY_AND_ASSIGNMENT_OPERATORS(PredicateAttrVal);
};

#undef TARG_CLASS
#undef TARG_NAMESPACE

} // End namespace TARGETING

#endif // __TARGETING_COMMON_PREDICATEATTRVAL_H
OpenPOWER on IntegriCloud