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

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

/include/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 December 2005
00009  *
00010  * Home:        http://recls.org/
00011  *
00012  * Copyright (c) 2004-2005, 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      0
00048 # define RECLS_VER_RECLSTL_STL_HPP_ROOT_SEQUENCE_REVISION   2
00049 # define RECLS_VER_RECLSTL_STL_HPP_ROOT_SEQUENCE_EDIT       13
00050 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00051 
00056 /* 
00057  * Includes
00058  */
00059 
00060 #ifndef RECLS_INCL_RECLS_STL_HPP_RECLS
00061 # include <recls/stl/recls.hpp>
00062 #endif /* !RECLS_INCL_RECLS_STL_HPP_RECLS */
00063 #ifndef RECLS_INCL_RECLS_STL_HPP_TRAITS
00064 # include <recls/stl/traits.hpp>
00065 #endif /* !RECLS_INCL_RECLS_STL_HPP_TRAITS */
00066 #include <stlsoft/new_allocator.hpp>
00067 #include <stlsoft/proxy_sequence.hpp>
00068 
00069 /* 
00070  * Namespace
00071  */
00072 
00073 #if !defined(RECLS_NO_NAMESPACE)
00074 namespace recls
00075 {
00076 
00077 namespace stl
00078 {
00079 #endif /* !RECLS_NO_NAMESPACE */
00080 
00081 /* 
00082  * Classes
00083  */
00084 
00085 // class basic_root_sequence
00092 template<   typename C
00093 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00094         ,   typename T = reclstl_traits<C>
00095         ,   typename A = stlsoft::new_allocator<C>
00096 #else
00097         ,   typename T /* = reclstl_traits<C> */
00098         ,   typename A /* = stlsoft::new_allocator<C> */
00099 #endif /* __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
00100         >
00101 class basic_root_sequence
00102 {
00105 public:
00107     typedef C                                                       char_type;
00109     typedef T                                                       traits_type;
00111     typedef A                                                       allocator_type;
00113     typedef basic_root_sequence<C, T, A>                            class_type;
00115     typedef char_type const                                         *value_type;
00116 private:
00117     struct proxy_traits_type
00118     {
00119         static recls_char_t const *make_value(recls_root_t const &root)
00120         {
00121             return root.name;
00122         }
00123     };
00124 
00125     typedef stlsoft::proxy_sequence<    const recls_root_t
00126                                     ,   recls_char_t const*
00127                                     ,   proxy_traits_type
00128                                     >                               sequence_type;
00129 public:
00131     typedef typename sequence_type::const_iterator                  const_iterator;
00133     typedef value_type                                              &reference;
00135     typedef value_type const                                        &const_reference;
00137     typedef size_t                                                  size_type;
00139 
00142 public:
00144     basic_root_sequence();
00146     ~basic_root_sequence();
00148 
00151 public:
00155     const_iterator  begin() const;
00159     const_iterator  end() const;
00161 
00164 public:
00166     size_type           size() const;
00168     recls_bool_t        empty() const;
00170     static size_type    max_size();
00172 
00175 private:
00176     recls_root_t    *m_roots;
00177     size_type       m_cRoots;
00179 
00180 // Not to be implemented
00181 private:
00182     basic_root_sequence(class_type const &);
00183     basic_root_sequence const &operator =(class_type const &);
00184 };
00185 
00186 /* 
00187  * Typedefs for commonly encountered types
00188  */
00189 
00191 typedef basic_root_sequence<recls_char_a_t, reclstl_traits<recls_char_a_t>, stlsoft::new_allocator<recls_char_a_t> >    root_sequence_a;
00193 typedef basic_root_sequence<recls_char_w_t, reclstl_traits<recls_char_w_t>, stlsoft::new_allocator<recls_char_w_t> >    root_sequence_w;
00195 typedef basic_root_sequence<recls_char_t,   reclstl_traits<recls_char_t>,   stlsoft::new_allocator<recls_char_t> >      root_sequence;
00196 
00198 // Shims
00199 
00210 template <typename C, typename T, typename A>
00211 inline recls_bool_t is_empty(basic_root_sequence<C, T, A> const &s)
00212 {
00213     return s.empty();
00214 }
00215 
00217 // Implementation
00218 
00219 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00220 
00221 // basic_root_sequence
00222 
00223 // Construction
00224 
00225 template <typename C, typename T, typename A>
00226 inline basic_root_sequence<C, T, A>::basic_root_sequence()
00227 #ifdef RECLS_COMPILER_IS_BORLAND
00228     : m_cRoots(26) // It fails to "see" Recls_GetRoots()
00229 #else /* ? compiler */
00230     : m_cRoots(Recls_GetRoots(NULL, 0))
00231 #endif /* compiler */
00232 {
00233     m_roots = new recls_root_t[m_cRoots];
00234 
00235     m_cRoots = Recls_GetRoots(m_roots, m_cRoots);
00236 }
00237 
00238 template <typename C, typename T, typename A>
00239 inline basic_root_sequence<C, T, A>::~basic_root_sequence()
00240 {
00241     delete [] m_roots;
00242 }
00243 
00244 // Iteration
00245 
00246 template <typename C, typename T, typename A>
00247 inline typename basic_root_sequence<C, T, A>::const_iterator basic_root_sequence<C, T, A>::begin() const
00248 {
00249     return const_iterator(&m_roots[0], &m_roots[m_cRoots]);
00250 }
00251 
00252 template <typename C, typename T, typename A>
00253 inline typename basic_root_sequence<C, T, A>::const_iterator basic_root_sequence<C, T, A>::end() const
00254 {
00255     return const_iterator();
00256 }
00257 
00258 // State
00259 
00260 template <typename C, typename T, typename A>
00261 inline typename basic_root_sequence<C, T, A>::size_type basic_root_sequence<C, T, A>::size() const
00262 {
00263     return m_cRoots;
00264 }
00265 
00266 template <typename C, typename T, typename A>
00267 inline recls_bool_t basic_root_sequence<C, T, A>::empty() const
00268 {
00269     return 0 == m_cRoots;
00270 }
00271 
00272 template <typename C, typename T, typename A>
00273 inline /* static */ typename basic_root_sequence<C, T, A>::size_type basic_root_sequence<C, T, A>::max_size()
00274 {
00275     return static_cast<size_type>(-1) / sizeof(value_type);
00276 }
00277 
00278 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00279 
00280 /* 
00281 
00282 #if !defined(RECLS_NO_NAMESPACE)
00283 } /* namespace stl */
00284 } /* namespace recls */
00285 #endif /* !RECLS_NO_NAMESPACE */
00286 
00287 /* 
00288 
00289 #endif /* RECLS_INCL_RECLSTL_STL_HPP_ROOT_SEQUENCE */
00290 
00291 /* 

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