(file) Return to ArrayInternal.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 martin 1.8 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.9 //
  3 martin 1.8 // Licensed to The Open Group (TOG) under one or more contributor license
  4            // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5            // this work for additional information regarding copyright ownership.
  6            // Each contributor licenses this file to you under the OpenPegasus Open
  7            // Source License; you may not use this file except in compliance with the
  8            // License.
  9 martin 1.9 //
 10 martin 1.8 // Permission is hereby granted, free of charge, to any person obtaining a
 11            // copy of this software and associated documentation files (the "Software"),
 12            // to deal in the Software without restriction, including without limitation
 13            // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14            // and/or sell copies of the Software, and to permit persons to whom the
 15            // Software is furnished to do so, subject to the following conditions:
 16 martin 1.9 //
 17 martin 1.8 // The above copyright notice and this permission notice shall be included
 18            // in all copies or substantial portions of the Software.
 19 martin 1.9 //
 20 martin 1.8 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.9 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.8 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23            // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24            // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25            // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26            // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.9 //
 28 martin 1.8 //////////////////////////////////////////////////////////////////////////
 29 kumpf  1.1 //
 30            //%/////////////////////////////////////////////////////////////////////////////
 31            
 32            #ifndef Pegasus_ArrayInternal_h
 33            #define Pegasus_ArrayInternal_h
 34            
 35            #include <Pegasus/Common/Config.h>
 36            #include <Pegasus/Common/Array.h>
 37 kumpf  1.2 #include <Pegasus/Common/CIMName.h>
 38 kumpf  1.1 
 39            PEGASUS_NAMESPACE_BEGIN
 40            
 41            #include <Pegasus/Common/ArrayImpl.h>
 42            
 43            template<class PEGASUS_ARRAY_T>
 44            Boolean operator==(
 45                const Array<PEGASUS_ARRAY_T>& x,
 46                const Array<PEGASUS_ARRAY_T>& y)
 47            {
 48                if (x.size() != y.size())
 49                    return false;
 50            
 51                for (Uint32 i = 0, n = x.size(); i < n; i++)
 52                {
 53                    if (!(x[i] == y[i]))
 54                        return false;
 55                }
 56            
 57                return true;
 58            }
 59 kumpf  1.1 
 60            template<class PEGASUS_ARRAY_T>
 61            Boolean Contains(const Array<PEGASUS_ARRAY_T>& a, const PEGASUS_ARRAY_T& x)
 62            {
 63                Uint32 n = a.size();
 64            
 65                for (Uint32 i = 0; i < n; i++)
 66                {
 67                    if (a[i] == x)
 68                        return true;
 69                }
 70            
 71                return false;
 72            }
 73            
 74            template<class PEGASUS_ARRAY_T>
 75 kumpf  1.7 void BubbleSort(Array<PEGASUS_ARRAY_T>& x)
 76 kumpf  1.1 {
 77                Uint32 n = x.size();
 78            
 79                if (n < 2)
 80                    return;
 81            
 82                for (Uint32 i = 0; i < n - 1; i++)
 83                {
 84                    for (Uint32 j = 0; j < n - 1; j++)
 85                    {
 86                        if (x[j] > x[j+1])
 87                        {
 88                            PEGASUS_ARRAY_T t = x[j];
 89 kumpf  1.2                 x[j] = x[j+1];
 90                            x[j+1] = t;
 91                        }
 92                    }
 93                }
 94            }
 95            
 96 kumpf  1.7 inline void BubbleSort(Array<CIMName>& x)
 97 kumpf  1.2 {
 98                Uint32 n = x.size();
 99            
100                if (n < 2)
101                    return;
102            
103                for (Uint32 i = 0; i < n - 1; i++)
104                {
105                    for (Uint32 j = 0; j < n - 1; j++)
106                    {
107                        if (x[j].getString() > x[j+1].getString())
108                        {
109                            CIMName t = x[j];
110                            x[j] = x[j+1];
111                            x[j+1] = t;
112                        }
113                    }
114                }
115            }
116            
117 kumpf  1.7 inline void BubbleSort(Array<CIMNamespaceName>& x)
118 kumpf  1.2 {
119                Uint32 n = x.size();
120            
121                if (n < 2)
122                    return;
123            
124                for (Uint32 i = 0; i < n - 1; i++)
125                {
126                    for (Uint32 j = 0; j < n - 1; j++)
127                    {
128                        if (x[j].getString() > x[j+1].getString())
129                        {
130                            CIMNamespaceName t = x[j];
131 kumpf  1.1                 x[j] = x[j+1];
132                            x[j+1] = t;
133                        }
134                    }
135                }
136            }
137            
138            #if 0
139            // Determine need for these functions
140            template<class PEGASUS_ARRAY_T>
141 kumpf  1.7 void Unique(Array<PEGASUS_ARRAY_T>& x)
142 kumpf  1.1 {
143                Array<PEGASUS_ARRAY_T> result;
144            
145                for (Uint32 i = 0, n = x.size(); i < n; i++)
146                {
147                    if (i == 0 || x[i] != x[i-1])
148                        result.append(x[i]);
149                }
150            
151                x.swap(result);
152            }
153            
154            template<class PEGASUS_ARRAY_T>
155            void Print(Array<PEGASUS_ARRAY_T>& x)
156            {
157                for (Uint32 i = 0, n = x.size(); i < n; i++)
158                    PEGASUS_STD(cout) << x[i] << PEGASUS_STD(endl);
159            }
160            #endif
161            
162            PEGASUS_NAMESPACE_END
163 kumpf  1.1 
164            #endif /* Pegasus_ArrayInternal_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2