C/C++ User's Journal Synesis Software 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 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  

/Mappings/STL/reclstl_root_sequence.h

Go to the documentation of this file.
00001 /* 
00002  * File:        reclstl_root_sequence.h
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:     24th April 2004
00009  *
00010  * Author:      Matthew Wilson, Synesis Software Pty Ltd.
00011  *
00012  * License:     (Licensed under the Synesis Software Standard Source License)
00013  *
00014  *              Copyright (C) 2002-2004, Synesis Software Pty Ltd.
00015  *
00016  *              All rights reserved.
00017  *
00018  *              www:        http://www.synesis.com.au/software
00019  *                          http://www.recls.org/
00020  *
00021  *              email:      submissions@recls.org  for submissions
00022  *                          admin@recls.org        for other enquiries
00023  *
00024  *              Redistribution and use in source and binary forms, with or
00025  *              without modification, are permitted provided that the following
00026  *              conditions are met:
00027  *
00028  *              (i) Redistributions of source code must retain the above
00029  *              copyright notice and contact information, this list of
00030  *              conditions and the following disclaimer.
00031  *
00032  *              (ii) Any derived versions of this software (howsoever modified)
00033  *              remain the sole property of Synesis Software.
00034  *
00035  *              (iii) Any derived versions of this software (howsoever modified)
00036  *              remain subject to all these conditions.
00037  *
00038  *              (iv) Neither the name of Synesis Software nor the names of any
00039  *              subdivisions, employees or agents of Synesis Software, nor the
00040  *              names of any other contributors to this software may be used to
00041  *              endorse or promote products derived from this software without
00042  *              specific prior written permission.
00043  *
00044  *              This source code is provided by Synesis Software "as is" and any
00045  *              warranties, whether expressed or implied, including, but not
00046  *              limited to, the implied warranties of merchantability and
00047  *              fitness for a particular purpose are disclaimed. In no event
00048  *              shall the Synesis Software be liable for any direct, indirect,
00049  *              incidental, special, exemplary, or consequential damages
00050  *              (including, but not limited to, procurement of substitute goods
00051  *              or services; loss of use, data, or profits; or business
00052  *              interruption) however caused and on any theory of liability,
00053  *              whether in contract, strict liability, or tort (including
00054  *              negligence or otherwise) arising in any way out of the use of
00055  *              this software, even if advised of the possibility of such
00056  *              damage.
00057  *
00058  * 
00059 
00060 
00061 #ifndef RECLS_INCL_H_RECLSTL_ROOT_SEQUENCE
00062 #define RECLS_INCL_H_RECLSTL_ROOT_SEQUENCE
00063 
00064 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00065 # define RECLS_VER_H_RECLSTL_ROOT_SEQUENCE_MAJOR    1
00066 # define RECLS_VER_H_RECLSTL_ROOT_SEQUENCE_MINOR    0
00067 # define RECLS_VER_H_RECLSTL_ROOT_SEQUENCE_REVISION 4
00068 # define RECLS_VER_H_RECLSTL_ROOT_SEQUENCE_EDIT     4
00069 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00070 
00075 /* 
00076  * Includes
00077  */
00078 
00079 #ifndef RECLS_INCL_H_RECLSTL
00080 # include "reclstl.h"
00081 #endif /* !RECLS_INCL_H_RECLSTL */
00082 #ifndef RECLS_INCL_H_RECLSTL_TRAITS
00083 # include "reclstl_traits.h"
00084 #endif /* !RECLS_INCL_H_RECLSTL_TRAITS */
00085 #ifndef _STLSOFT_INCL_H_STLSOFT_NEW_ALLOCATOR
00086 # include <stlsoft_new_allocator.h>
00087 #endif /* !_STLSOFT_INCL_H_STLSOFT_NEW_ALLOCATOR */
00088 
00089 /* 
00090  * Namespace
00091  */
00092 
00093 #if !defined(RECLS_NO_NAMESPACE)
00094 namespace recls
00095 {
00096 
00097 namespace stl
00098 {
00099 #endif /* !RECLS_NO_NAMESPACE */
00100 
00101 /* 
00102  * Classes
00103  */
00104 
00105 // class basic_root_sequence
00112 template<   typename C
00113 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00114         ,   typename T = reclstl_traits<C>
00115         ,   typename A = stlsoft::new_allocator<C>
00116 #else
00117         ,   typename T /* = reclstl_traits<C> */
00118         ,   typename A /* = stlsoft::new_allocator<C> */
00119 #endif /* __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
00120         >
00121 class basic_root_sequence
00122 {
00125 public:
00127     typedef C                                                       char_type;
00129     typedef T                                                       traits_type;
00131     typedef A                                                       allocator_type;
00133     typedef basic_root_sequence<C, T, A>                            class_type;
00135     typedef char_type const                                         *value_type;
00136 private:
00137     struct proxy_traits_type
00138     {
00139         static recls_char_t const *make_value(recls_root_t const &root)
00140         {
00141             return root.name;
00142         }
00143     };
00144 
00145     typedef stlsoft::proxy_sequence<    const recls_root_t
00146                                     ,   recls_char_t const*
00147                                     ,   proxy_traits_type
00148                                     >                               sequence_type;
00149 public:
00151     typedef typename sequence_type::const_iterator                  const_iterator;
00153     typedef value_type                                              &reference;
00155     typedef value_type const                                        &const_reference;
00157     typedef size_t                                                  size_type;
00159 
00162 public:
00164     basic_root_sequence();
00166     ~basic_root_sequence();
00168 
00171 public:
00175     const_iterator  begin() const;
00179     const_iterator  end() const;
00181 
00184 public:
00186     size_type           size() const;
00188     recls_bool_t        empty() const;
00190     static size_type    max_size();
00192 
00195 private:
00196     recls_root_t    *m_roots;
00197     size_type       m_cRoots;
00199 
00200 // Not to be implemented
00201 private:
00202     basic_root_sequence(class_type const &);
00203     basic_root_sequence const &operator =(class_type const &);
00204 };
00205 
00206 /* 
00207  * Typedefs for commonly encountered types
00208  */
00209 
00211 typedef basic_root_sequence<recls_char_a_t, reclstl_traits<recls_char_a_t>, stlsoft::new_allocator<recls_char_a_t> >    root_sequence_a;
00213 typedef basic_root_sequence<recls_char_w_t, reclstl_traits<recls_char_w_t>, stlsoft::new_allocator<recls_char_w_t> >    root_sequence_w;
00215 typedef basic_root_sequence<recls_char_t,   reclstl_traits<recls_char_t>,   stlsoft::new_allocator<recls_char_t> >      root_sequence;
00216 
00218 // Shims
00219 
00230 template <typename C, typename T, typename A>
00231 inline recls_bool_t is_empty(basic_root_sequence<C, T, A> const &s)
00232 {
00233     return s.empty();
00234 }
00235 
00237 // Implementation
00238 
00239 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00240 
00241 // basic_root_sequence
00242 
00243 // Construction
00244 
00245 template <typename C, typename T, typename A>
00246 inline basic_root_sequence<C, T, A>::basic_root_sequence()
00247 #ifdef RECLS_COMPILER_IS_BORLAND
00248     : m_cRoots(26) // It fails to "see" Recls_GetRoots()
00249 #else /* ? compiler */
00250     : m_cRoots(Recls_GetRoots(NULL, 0))
00251 #endif /* compiler */
00252 {
00253     m_roots = new recls_root_t[m_cRoots];
00254 
00255     m_cRoots = Recls_GetRoots(m_roots, m_cRoots);
00256 }
00257 
00258 template <typename C, typename T, typename A>
00259 inline basic_root_sequence<C, T, A>::~basic_root_sequence()
00260 {
00261     delete [] m_roots;
00262 }
00263 
00264 // Iteration
00265 
00266 template <typename C, typename T, typename A>
00267 inline typename basic_root_sequence<C, T, A>::const_iterator basic_root_sequence<C, T, A>::begin() const
00268 {
00269     return sequence_type(&m_roots[0], &m_roots[m_cRoots]).begin();
00270 }
00271 
00272 template <typename C, typename T, typename A>
00273 inline typename basic_root_sequence<C, T, A>::const_iterator basic_root_sequence<C, T, A>::end() const
00274 {
00275     return sequence_type(&m_roots[0], &m_roots[m_cRoots]).end();
00276 }
00277 
00278 // State
00279 
00280 template <typename C, typename T, typename A>
00281 inline typename basic_root_sequence<C, T, A>::size_type basic_root_sequence<C, T, A>::size() const
00282 {
00283     return m_cRoots;
00284 }
00285 
00286 template <typename C, typename T, typename A>
00287 inline recls_bool_t basic_root_sequence<C, T, A>::empty() const
00288 {
00289     return 0 == m_cRoots;
00290 }
00291 
00292 template <typename C, typename T, typename A>
00293 inline /* static */ typename basic_root_sequence<C, T, A>::size_type basic_root_sequence<C, T, A>::max_size()
00294 {
00295     return static_cast<size_type>(-1) / sizeof(value_type);
00296 }
00297 
00298 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00299 
00300 /* 
00301 
00302 #if !defined(RECLS_NO_NAMESPACE)
00303 } /* namespace stl */
00304 } /* namespace recls */
00305 #endif /* !RECLS_NO_NAMESPACE */
00306 
00307 /* 
00308 
00309 #endif /* RECLS_INCL_H_RECLSTL_ROOT_SEQUENCE */
00310 
00311 /* 

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