Merge pull request #25959 from neo1973/TagLib_deprecation_warnings
[xbmc.git] / lib / libUPnP / Neptune / Source / Core / NptCommon.h
blob9137d3127c6b9a2088ded006a68dfe437d1b2c4d
1 /*****************************************************************
3 | Neptune - Common Definitions
5 | Copyright (c) 2002-2008, Axiomatic Systems, LLC.
6 | All rights reserved.
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 /*----------------------------------------------------------------------
36 | includes
37 +---------------------------------------------------------------------*/
38 #include "NptTypes.h"
39 #include "NptResults.h"
41 /*----------------------------------------------------------------------
42 | NPT_ObjectDeleter
43 +---------------------------------------------------------------------*/
44 template <class T>
45 class NPT_ObjectDeleter {
46 public:
47 void operator()(T* object) const {
48 delete object;
52 /*----------------------------------------------------------------------
53 | NPT_ObjectComparator
54 +---------------------------------------------------------------------*/
55 template <class T>
56 class NPT_ObjectComparator {
57 public:
58 NPT_ObjectComparator(T& object) : m_Object(object) {}
59 bool operator()(const T& object) const {
60 return object == m_Object;
62 private:
63 T& m_Object;
66 /*----------------------------------------------------------------------
67 | NPT_ContainerFind
68 +---------------------------------------------------------------------*/
69 template <typename T, typename P>
70 NPT_Result NPT_ContainerFind(T& container,
71 const P& predicate,
72 typename T::Element& item,
73 NPT_Ordinal n=0)
75 typename T::Iterator found = container.Find(predicate, n);
76 if (found) {
77 item = *found;
78 return NPT_SUCCESS;
79 } else {
80 return NPT_ERROR_NO_SUCH_ITEM;
84 /*----------------------------------------------------------------------
85 | NPT_ContainerFind
86 +---------------------------------------------------------------------*/
87 template <typename T, typename P>
88 NPT_Result NPT_ContainerFind(T& container,
89 const P& predicate,
90 typename T::Iterator& iter,
91 NPT_Ordinal n=0)
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
102 public:
103 // methods
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;
111 return true;
112 } else {
113 return false;
117 private:
118 // members
119 NPT_Result m_ConditionResult;
120 NPT_Result m_ReturnValue;
123 /*----------------------------------------------------------------------
124 | NPT_UntilResultNotEquals
125 +---------------------------------------------------------------------*/
126 class NPT_UntilResultNotEquals
128 public:
129 // methods
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;
135 return true;
136 } else {
137 return false;
141 private:
142 // members
143 NPT_Result m_ConditionResult;
146 /*----------------------------------------------------------------------
147 | NPT_PropertyValue
148 +---------------------------------------------------------------------*/
149 class NPT_PropertyValue
151 public:
152 // typedefs
153 typedef enum {UNKNOWN, INTEGER, STRING} Type;
155 // methods
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) {}
160 // members
161 Type m_Type;
162 union {
163 int m_Integer;
164 const char* m_String;
168 #endif // _NPT_COMMON_H_