blocxx
Enumeration.hpp
Go to the documentation of this file.
1/*******************************************************************************
2* Copyright (C) 2005, Vintela, Inc. All rights reserved.
3* Copyright (C) 2006, Novell, Inc. All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7*
8* * Redistributions of source code must retain the above copyright notice,
9* this list of conditions and the following disclaimer.
10* * Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* * Neither the name of
14* Vintela, Inc.,
15* nor Novell, Inc.,
16* nor the names of its contributors or employees may be used to
17* endorse or promote products derived from this software without
18* specific prior written permission.
19*
20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30* POSSIBILITY OF SUCH DAMAGE.
31*******************************************************************************/
32
33
37
38#ifndef BLOCXX_ENUMERATION_HPP_INCLUDE_GUARD_
39#define BLOCXX_ENUMERATION_HPP_INCLUDE_GUARD_
40#include "blocxx/BLOCXX_config.h"
43
44#include <iterator> // for the iterator tags
45
46namespace BLOCXX_NAMESPACE
47{
48
49template <class T>
51{
52public:
57 {
58 }
59 void nextElement(T& out)
60 {
62 out.readObject(*m_Data.rdbuf());
63 --m_size;
64 }
66 {
68 T retval;
69 retval.readObject(*m_Data.rdbuf());
70 --m_size;
71 return retval;
72 }
73 void addElement( const T& arg )
74 {
75 arg.writeObject(*m_Data.rdbuf());
76 ++m_size;
77 }
78private:
79 // Prevent copying or assignment
82};
83
84template <class T>
86{
87public:
90 {
91 }
92 bool hasMoreElements() const
93 {
94 return m_impl->hasMoreElements();
95 }
96 void nextElement(T& arg)
97 {
98 m_impl->nextElement(arg);
99 }
101 {
102 return m_impl->nextElement();
103 }
104 size_t numberOfElements() const
105 {
106 return m_impl->numberOfElements();
107 }
108 void addElement(const T& arg)
109 {
110 m_impl->addElement(arg);
111 }
112 void clear()
113 {
114 m_impl->clear();
115 }
116 bool usingTempFile() const
117 {
118 return m_impl->usingTempFile();
119 }
120private:
122};
123
124template <class T>
126{
127public:
129 typedef std::input_iterator_tag iterator_category;
130 typedef T value_type;
131 typedef const T* pointer;
132 typedef const T& reference;
133 typedef ptrdiff_t difference_type;
141
142 // compiler generated copy ctor is what we want.
143 // compiler generated copy-assignment operator= is what we want.
144
146 {
147 return m_value;
148 }
150 {
151 return &(operator*());
152 }
154 {
155 m_read();
156 return *this;
157 }
159 {
160 Enumeration_input_iterator tmp = *this;
161 m_read();
162 return tmp;
163 }
165 {
166 return(m_ok == x.m_ok) && (!m_ok || m_enumeration == x.m_enumeration);
167 }
168private:
171 bool m_ok;
172 void m_read()
173 {
174 m_ok = (m_enumeration && m_enumeration->hasMoreElements()) ? true : false;
175 if (m_ok)
176 {
177 m_enumeration->nextElement(m_value);
178 }
179 }
180};
181
182template <class T>
183inline bool
186{
187 return x.m_equal(y);
188}
189
190template <class T>
191inline bool
194{
195 return !x.m_equal(y);
196}
197
198template <class T>
200{
201public:
203 typedef std::output_iterator_tag iterator_category;
204 typedef void value_type;
205 typedef void difference_type;
206 typedef void pointer;
207 typedef void reference;
212 {
213 m_enumeration->addElement(value);
214 return *this;
215 }
217 {
218 return *this;
219 }
221 {
222 return *this;
223 }
225 {
226 return *this;
227 }
228private:
230};
231
232template <class Container>
237
238} // end namespace BLOCXX_NAMESPACE
239
240#endif
Enumeration_input_iterator & operator++()
Enumeration_input_iterator operator++(int)
bool m_equal(const Enumeration_input_iterator &x) const
Enumeration_insert_iterator< T > & operator++(int)
Enumeration_insert_iterator< T > & operator++()
Enumeration_insert_iterator< T > & operator=(const T &value)
Enumeration_insert_iterator< T > & operator*()
void addElement(const T &arg)
IntrusiveReference< TempFileEnumerationImpl< String > > m_impl
TempFileEnumerationImpl< T > & operator=(const TempFileEnumerationImpl< T > &)
TempFileEnumerationImpl(const TempFileEnumerationImpl< T > &)
Taken from RFC 1321.
bool operator==(const Array< T > &x, const Array< T > &y)
Enumeration_insert_iterator< Container > Enumeration_inserter(Enumeration< Container > &x)
bool operator!=(const Array< T > &x, const Array< T > &y)
Determine two Arrays are not equal.
Definition Array.hpp:446