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 
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 
46 namespace BLOCXX_NAMESPACE
47 {
48 
49 template <class T>
51 {
52 public:
54  {
55  }
57  {
58  }
59  void nextElement(T& out)
60  {
61  throwIfEmpty();
62  out.readObject(*m_Data.rdbuf());
63  --m_size;
64  }
66  {
67  throwIfEmpty();
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  }
78 private:
79  // Prevent copying or assignment
82 };
83 
84 template <class T>
86 {
87 public:
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  }
120 private:
122 };
123 
124 template <class T>
126 {
127 public:
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;
135  {
136  }
138  {
139  m_read();
140  }
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  }
164  bool m_equal(const Enumeration_input_iterator& x) const
165  {
166  return(m_ok == x.m_ok) && (!m_ok || m_enumeration == x.m_enumeration);
167  }
168 private:
171  bool m_ok;
172  void m_read()
173  {
174  m_ok = (m_enumeration && m_enumeration->hasMoreElements()) ? true : false;
175  if (m_ok)
176  {
178  }
179  }
180 };
181 
182 template <class T>
183 inline bool
186 {
187  return x.m_equal(y);
188 }
189 
190 template <class T>
191 inline bool
194 {
195  return !x.m_equal(y);
196 }
197 
198 template <class T>
200 {
201 public:
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;
209  {
210  }
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  }
228 private:
230 };
231 
232 template <class Container>
234 {
236 }
237 
238 } // end namespace BLOCXX_NAMESPACE
239 
240 #endif