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:     11th March 2005
00009  *
00010  * Home:        http://recls.org/
00011  *
00012  * Copyright 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   1
00049 # define RECLS_VER_RECLSTL_STL_HPP_ROOT_SEQUENCE_EDIT       11
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 #ifndef STLSOFT_INCL_H_STLSOFT_NEW_ALLOCATOR
00067 # include <stlsoft_new_allocator.h>
00068 #endif /* !STLSOFT_INCL_H_STLSOFT_NEW_ALLOCATOR */
00069 #ifndef STLSOFT_INCL_H_STLSOFT_PROXY_SEQUENCE
00070 # include <stlsoft_proxy_sequence.h>
00071 #endif /* !STLSOFT_INCL_H_STLSOFT_PROXY_SEQUENCE */
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
00096 template<   typename C
00097 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00098         ,   typename T = reclstl_traits<C>
00099         ,   typename A = stlsoft::new_allocator<C>
00100 #else
00101         ,   typename T /* = reclstl_traits<C> */
00102         ,   typename A /* = stlsoft::new_allocator<C> */
00103 #endif /* __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
00104         >
00105 class basic_root_sequence
00106 {
00109 public:
00111     typedef C                                                       char_type;
00113     typedef T                                                       traits_type;
00115     typedef A                                                       allocator_type;
00117     typedef basic_root_sequence<C, T, A>                            class_type;
00119     typedef char_type const                                         *value_type;
00120 private:
00121     struct proxy_traits_type
00122     {
00123         static recls_char_t const *make_value(recls_root_t const &root)
00124         {
00125             return root.name;
00126         }
00127     };
00128 
00129     typedef stlsoft::proxy_sequence<    const recls_root_t
00130                                     ,   recls_char_t const*
00131                                     ,   proxy_traits_type
00132                                     >                               sequence_type;
00133 public:
00135     typedef typename sequence_type::const_iterator                  const_iterator;
00137     typedef value_type                                              &reference;
00139     typedef value_type const                                        &const_reference;
00141     typedef size_t                                                  size_type;
00143 
00146 public:
00148     basic_root_sequence();
00150     ~basic_root_sequence();
00152 
00155 public:
00159     const_iterator  begin() const;
00163     const_iterator  end() const;
00165 
00168 public:
00170     size_type           size() const;
00172     recls_bool_t        empty() const;
00174     static size_type    max_size();
00176 
00179 private:
00180     recls_root_t    *m_roots;
00181     size_type       m_cRoots;
00183 
00184 // Not to be implemented
00185 private:
00186     basic_root_sequence(class_type const &);
00187     basic_root_sequence const &operator =(class_type const &);
00188 };
00189 
00190 /* 
00191  * Typedefs for commonly encountered types
00192  */
00193 
00195 typedef basic_root_sequence<recls_char_a_t, reclstl_traits<recls_char_a_t>, stlsoft::new_allocator<recls_char_a_t> >    root_sequence_a;
00197 typedef basic_root_sequence<recls_char_w_t, reclstl_traits<recls_char_w_t>, stlsoft::new_allocator<recls_char_w_t> >    root_sequence_w;
00199 typedef basic_root_sequence<recls_char_t,   reclstl_traits<recls_char_t>,   stlsoft::new_allocator<recls_char_t> >      root_sequence;
00200 
00202 // Shims
00203 
00214 template <typename C, typename T, typename A>
00215 inline recls_bool_t is_empty(basic_root_sequence<C, T, A> const &s)
00216 {
00217     return s.empty();
00218 }
00219 
00221 // Implementation
00222 
00223 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00224 
00225 // basic_root_sequence
00226 
00227 // Construction
00228 
00229 template <typename C, typename T, typename A>
00230 inline basic_root_sequence<C, T, A>::basic_root_sequence()
00231 #ifdef RECLS_COMPILER_IS_BORLAND
00232     : m_cRoots(26) // It fails to "see" Recls_GetRoots()
00233 #else /* ? compiler */
00234     : m_cRoots(Recls_GetRoots(NULL, 0))
00235 #endif /* compiler */
00236 {
00237     m_roots = new recls_root_t[m_cRoots];
00238 
00239     m_cRoots = Recls_GetRoots(m_roots, m_cRoots);
00240 }
00241 
00242 template <typename C, typename T, typename A>
00243 inline basic_root_sequence<C, T, A>::~basic_root_sequence()
00244 {
00245     delete [] m_roots;
00246 }
00247 
00248 // Iteration
00249 
00250 template <typename C, typename T, typename A>
00251 inline typename basic_root_sequence<C, T, A>::const_iterator basic_root_sequence<C, T, A>::begin() const
00252 {
00253     return const_iterator(&m_roots[0], &m_roots[m_cRoots]);
00254 }
00255 
00256 template <typename C, typename T, typename A>
00257 inline typename basic_root_sequence<C, T, A>::const_iterator basic_root_sequence<C, T, A>::end() const
00258 {
00259     return const_iterator();
00260 }
00261 
00262 // State
00263 
00264 template <typename C, typename T, typename A>
00265 inline typename basic_root_sequence<C, T, A>::size_type basic_root_sequence<C, T, A>::size() const
00266 {
00267     return m_cRoots;
00268 }
00269 
00270 template <typename C, typename T, typename A>
00271 inline recls_bool_t basic_root_sequence<C, T, A>::empty() const
00272 {
00273     return 0 == m_cRoots;
00274 }
00275 
00276 template <typename C, typename T, typename A>
00277 inline /* static */ typename basic_root_sequence<C, T, A>::size_type basic_root_sequence<C, T, A>::max_size()
00278 {
00279     return static_cast<size_type>(-1) / sizeof(value_type);
00280 }
00281 
00282 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00283 
00284 /* 
00285 
00286 #if !defined(RECLS_NO_NAMESPACE)
00287 } /* namespace stl */
00288 } /* namespace recls */
00289 #endif /* !RECLS_NO_NAMESPACE */
00290 
00291 /* 
00292 
00293 #endif /* RECLS_INCL_RECLSTL_STL_HPP_ROOT_SEQUENCE */
00294 
00295 /* 

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