C/C++ User's Journal STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - where the Standard Template Library meets the Active Template Library COMSTL - where the Standard Template Library meets the Component Object Model
Synesis Software InetSTL - where the Standard Template Library meets the Internet UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

recls/stl/root_sequence.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        recls/stl/root_sequence.hpp
00003  *
00004  * Purpose:     Contains the basic_root_sequence template class, and ANSI
00005  *              and Unicode specialisations thereof.
00006  *
00007  * Created:     25th March 2004
00008  * Updated:     17th June 2006
00009  *
00010  * Home:        http://recls.org/
00011  *
00012  * Copyright (c) 2004-2006, Matthew Wilson and Synesis Software
00013  * All rights reserved.
00014  *
00015  * Redistribution and use in source and binary forms, with or without 
00016  * modification, are permitted provided that the following conditions are met:
00017  *
00018  * - Redistributions of source code must retain the above copyright notice, this
00019  *   list of conditions and the following disclaimer. 
00020  * - Redistributions in binary form must reproduce the above copyright notice,
00021  *   this list of conditions and the following disclaimer in the documentation
00022  *   and/or other materials provided with the distribution.
00023  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00024  *   any contributors may be used to endorse or promote products derived from
00025  *   this software without specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  *
00039  * ////////////////////////////////////////////////////////////////////////// */
00040 
00041 
00042 #ifndef RECLS_INCL_RECLSTL_STL_HPP_ROOT_SEQUENCE
00043 #define RECLS_INCL_RECLSTL_STL_HPP_ROOT_SEQUENCE
00044 
00045 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00046 # define RECLS_VER_RECLSTL_STL_HPP_ROOT_SEQUENCE_MAJOR      3
00047 # define RECLS_VER_RECLSTL_STL_HPP_ROOT_SEQUENCE_MINOR      1
00048 # define RECLS_VER_RECLSTL_STL_HPP_ROOT_SEQUENCE_REVISION   1
00049 # define RECLS_VER_RECLSTL_STL_HPP_ROOT_SEQUENCE_EDIT       15
00050 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00051 
00060 /* /////////////////////////////////////////////////////////////////////////////
00061  * Includes
00062  */
00063 
00064 #ifndef RECLS_INCL_RECLS_STL_HPP_RECLS
00065 # include <recls/stl/recls.hpp>
00066 #endif /* !RECLS_INCL_RECLS_STL_HPP_RECLS */
00067 #ifndef RECLS_INCL_RECLS_STL_HPP_TRAITS
00068 # include <recls/stl/traits.hpp>
00069 #endif /* !RECLS_INCL_RECLS_STL_HPP_TRAITS */
00070 #include <stlsoft/memory/new_allocator.hpp>
00071 #include <stlsoft/proxy_sequence.hpp>
00072 
00073 /* /////////////////////////////////////////////////////////////////////////////
00074  * Namespace
00075  */
00076 
00077 #if !defined(RECLS_NO_NAMESPACE)
00078 namespace recls
00079 {
00080 
00081 namespace stl
00082 {
00083 #endif /* !RECLS_NO_NAMESPACE */
00084 
00085 /* /////////////////////////////////////////////////////////////////////////////
00086  * Classes
00087  */
00088 
00089 // class basic_root_sequence
00104 template<   typename C
00105 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00106         ,   typename T = reclstl_traits<C>
00107         ,   typename A = stlsoft::new_allocator<C>
00108 #else
00109         ,   typename T /* = reclstl_traits<C> */
00110         ,   typename A /* = stlsoft::new_allocator<C> */
00111 #endif /* __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
00112         >
00113 class basic_root_sequence
00114 {
00117 public:
00119     typedef C                                                       char_type;
00121     typedef T                                                       traits_type;
00123     typedef A                                                       allocator_type;
00125     typedef basic_root_sequence<C, T, A>                            class_type;
00127     typedef char_type const                                         *value_type;
00128 private:
00129     struct proxy_traits_type
00130     {
00131         static recls_char_t const *make_value(recls_root_t const &root)
00132         {
00133             return root.name;
00134         }
00135     };
00136 
00137     typedef stlsoft::proxy_sequence<    const recls_root_t
00138                                     ,   recls_char_t const*
00139                                     ,   proxy_traits_type
00140                                     >                               sequence_type;
00141 public:
00143     typedef typename sequence_type::const_iterator                  const_iterator;
00145     typedef value_type                                              &reference;
00147     typedef value_type const                                        &const_reference;
00149     typedef size_t                                                  size_type;
00151 
00154 public:
00157     basic_root_sequence();
00160     basic_root_sequence(unsigned flags);
00162     ~basic_root_sequence();
00164 
00167 public:
00171     const_iterator  begin() const;
00175     const_iterator  end() const;
00177 
00180 public:
00182     size_type           size() const;
00184     recls_bool_t        empty() const;
00186     static size_type    max_size();
00188 
00191 private:
00192     recls_root_t    *m_roots;
00193     size_type       m_cRoots;
00195 
00196 // Not to be implemented
00197 private:
00198     basic_root_sequence(class_type const &);
00199     basic_root_sequence const &operator =(class_type const &);
00200 };
00201 
00202 /* /////////////////////////////////////////////////////////////////////////////
00203  * Typedefs for commonly encountered types
00204  */
00205 
00207 typedef basic_root_sequence<recls_char_a_t, reclstl_traits<recls_char_a_t>, stlsoft::new_allocator<recls_char_a_t> >    root_sequence_a;
00209 typedef basic_root_sequence<recls_char_w_t, reclstl_traits<recls_char_w_t>, stlsoft::new_allocator<recls_char_w_t> >    root_sequence_w;
00211 typedef basic_root_sequence<recls_char_t,   reclstl_traits<recls_char_t>,   stlsoft::new_allocator<recls_char_t> >      root_sequence;
00212 
00214 // Shims
00215 
00226 template <typename C, typename T, typename A>
00227 inline recls_bool_t is_empty(basic_root_sequence<C, T, A> const &s)
00228 {
00229     return s.empty();
00230 }
00231 
00233 // Implementation
00234 
00235 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00236 
00237 // basic_root_sequence
00238 
00239 // Construction
00240 
00241 template <typename C, typename T, typename A>
00242 inline basic_root_sequence<C, T, A>::basic_root_sequence()
00243 #ifdef RECLS_COMPILER_IS_BORLAND
00244     : m_cRoots(26) // It fails to "see" Recls_GetRoots()
00245 #else /* ? compiler */
00246     : m_cRoots(Recls_GetRoots(NULL, 0))
00247 #endif /* compiler */
00248 {
00249     m_roots = new recls_root_t[m_cRoots];
00250 
00251     m_cRoots = Recls_GetRoots(m_roots, m_cRoots);
00252 }
00253 
00254 template <typename C, typename T, typename A>
00255 inline basic_root_sequence<C, T, A>::basic_root_sequence(unsigned flags)
00256 #ifdef RECLS_COMPILER_IS_BORLAND
00257     : m_cRoots(26) // It fails to "see" Recls_GetRoots()
00258 #else /* ? compiler */
00259     : m_cRoots(Recls_GetSelectedRoots(NULL, 0, flags))
00260 #endif /* compiler */
00261 {
00262     m_roots = new recls_root_t[m_cRoots];
00263 
00264     m_cRoots = Recls_GetSelectedRoots(m_roots, m_cRoots, flags);
00265 }
00266 
00267 template <typename C, typename T, typename A>
00268 inline basic_root_sequence<C, T, A>::~basic_root_sequence()
00269 {
00270     delete [] m_roots;
00271 }
00272 
00273 // Iteration
00274 
00275 template <typename C, typename T, typename A>
00276 inline typename basic_root_sequence<C, T, A>::const_iterator basic_root_sequence<C, T, A>::begin() const
00277 {
00278     return const_iterator(&m_roots[0], &m_roots[m_cRoots]);
00279 }
00280 
00281 template <typename C, typename T, typename A>
00282 inline typename basic_root_sequence<C, T, A>::const_iterator basic_root_sequence<C, T, A>::end() const
00283 {
00284     return const_iterator();
00285 }
00286 
00287 // State
00288 
00289 template <typename C, typename T, typename A>
00290 inline typename basic_root_sequence<C, T, A>::size_type basic_root_sequence<C, T, A>::size() const
00291 {
00292     return m_cRoots;
00293 }
00294 
00295 template <typename C, typename T, typename A>
00296 inline recls_bool_t basic_root_sequence<C, T, A>::empty() const
00297 {
00298     return 0 == m_cRoots;
00299 }
00300 
00301 template <typename C, typename T, typename A>
00302 inline /* static */ typename basic_root_sequence<C, T, A>::size_type basic_root_sequence<C, T, A>::max_size()
00303 {
00304     return static_cast<size_type>(-1) / sizeof(value_type);
00305 }
00306 
00307 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00308 
00309 /* ////////////////////////////////////////////////////////////////////////// */
00310 
00311 #if !defined(RECLS_NO_NAMESPACE)
00312 } /* namespace stl */
00313 } /* namespace recls */
00314 #endif /* !RECLS_NO_NAMESPACE */
00315 
00316 /* ////////////////////////////////////////////////////////////////////////// */
00317 
00318 #endif /* RECLS_INCL_RECLSTL_STL_HPP_ROOT_SEQUENCE */
00319 
00320 /* ////////////////////////////////////////////////////////////////////////// */

recls Library documentation © Synesis Software Pty Ltd, 2001-2006