1 /*****************************************************************
3 | Neptune - Common Definitions
5 | Copyright (c) 2002-2008, Axiomatic Systems, LLC.
8 | Redistribution and use in source and binary forms, with or without
9 | modification, are permitted provided that the following conditions are met:
10 | * Redistributions of source code must retain the above copyright
11 | notice, this list of conditions and the following disclaimer.
12 | * Redistributions in binary form must reproduce the above copyright
13 | notice, this list of conditions and the following disclaimer in the
14 | documentation and/or other materials provided with the distribution.
15 | * Neither the name of Axiomatic Systems nor the
16 | names of its contributors may be used to endorse or promote products
17 | derived from this software without specific prior written permission.
19 | THIS SOFTWARE IS PROVIDED BY AXIOMATIC SYSTEMS ''AS IS'' AND ANY
20 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL AXIOMATIC SYSTEMS BE LIABLE FOR ANY
23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 ****************************************************************/
32 #ifndef _NPT_COMMON_H_
33 #define _NPT_COMMON_H_
35 /*----------------------------------------------------------------------
37 +---------------------------------------------------------------------*/
39 #include "NptResults.h"
41 /*----------------------------------------------------------------------
43 +---------------------------------------------------------------------*/
45 class NPT_ObjectDeleter
{
47 void operator()(T
* object
) const {
52 /*----------------------------------------------------------------------
53 | NPT_ObjectComparator
54 +---------------------------------------------------------------------*/
56 class NPT_ObjectComparator
{
58 NPT_ObjectComparator(T
& object
) : m_Object(object
) {}
59 bool operator()(const T
& object
) const {
60 return object
== m_Object
;
66 /*----------------------------------------------------------------------
68 +---------------------------------------------------------------------*/
69 template <typename T
, typename P
>
70 NPT_Result
NPT_ContainerFind(T
& container
,
72 typename
T::Element
& item
,
75 typename
T::Iterator found
= container
.Find(predicate
, n
);
80 return NPT_ERROR_NO_SUCH_ITEM
;
84 /*----------------------------------------------------------------------
86 +---------------------------------------------------------------------*/
87 template <typename T
, typename P
>
88 NPT_Result
NPT_ContainerFind(T
& container
,
90 typename
T::Iterator
& iter
,
93 iter
= container
.Find(predicate
, n
);
94 return iter
?NPT_SUCCESS
:NPT_ERROR_NO_SUCH_ITEM
;
97 /*----------------------------------------------------------------------
98 | NPT_UntilResultEquals
99 +---------------------------------------------------------------------*/
100 class NPT_UntilResultEquals
104 NPT_UntilResultEquals(NPT_Result condition_result
,
105 NPT_Result return_value
= NPT_SUCCESS
) :
106 m_ConditionResult(condition_result
),
107 m_ReturnValue(return_value
) {}
108 bool operator()(NPT_Result result
, NPT_Result
& return_value
) const {
109 if (result
== m_ConditionResult
) {
110 return_value
= m_ReturnValue
;
119 NPT_Result m_ConditionResult
;
120 NPT_Result m_ReturnValue
;
123 /*----------------------------------------------------------------------
124 | NPT_UntilResultNotEquals
125 +---------------------------------------------------------------------*/
126 class NPT_UntilResultNotEquals
130 NPT_UntilResultNotEquals(NPT_Result condition_result
) :
131 m_ConditionResult(condition_result
) {}
132 bool operator()(NPT_Result result
, NPT_Result
& return_value
) const {
133 if (result
!= m_ConditionResult
) {
134 return_value
= result
;
143 NPT_Result m_ConditionResult
;
146 /*----------------------------------------------------------------------
148 +---------------------------------------------------------------------*/
149 class NPT_PropertyValue
153 typedef enum {UNKNOWN
, INTEGER
, STRING
} Type
;
156 NPT_PropertyValue() : m_Type(UNKNOWN
), m_Integer(0) {}
157 NPT_PropertyValue(int value
) : m_Type(INTEGER
), m_Integer(value
) {}
158 NPT_PropertyValue(const char* value
) : m_Type(STRING
), m_String(value
) {}
164 const char* m_String
;
168 #endif // _NPT_COMMON_H_