STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - Template Software for the Active Template Library COMSTL - The Standard Template Library meets the Component Object Model .netSTL - Standard Template Library meets the Microsoft.NET Common Language Runtime InetSTL - The Standard Template Library meets WinInet MFCSTL - Template Software for the Microsoft Foundation Classes 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  

stlsoft_sequence_container_veneer.h

Go to the documentation of this file.
00001 /* 
00002  * File:        stlsoft_sequence_container_veneer.h
00003  *
00004  * Purpose:     RRID (veneer for sequence containers)
00005  *
00006  * Created:     2nd October 2002
00007  * Updated:     11th September 2004
00008  *
00009  * Home:        http://stlsoft.org/
00010  *
00011  * Copyright (c) 2002-2004, Matthew Wilson and Synesis Software
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without
00015  * modification, are permitted provided that the following conditions are met:
00016  *
00017  * - Redistributions of source code must retain the above copyright notice, this
00018  *   list of conditions and the following disclaimer.
00019  * - Redistributions in binary form must reproduce the above copyright notice,
00020  *   this list of conditions and the following disclaimer in the documentation
00021  *   and/or other materials provided with the distribution.
00022  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00023  *   any contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * 
00039 
00040 
00044 
00045 #ifndef STLSOFT_INCL_H_STLSOFT_SEQUENCE_CONTAINER_VENEER
00046 #define STLSOFT_INCL_H_STLSOFT_SEQUENCE_CONTAINER_VENEER
00047 
00048 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00049 # define STLSOFT_VER_H_STLSOFT_SEQUENCE_CONTAINER_VENEER_MAJOR      2
00050 # define STLSOFT_VER_H_STLSOFT_SEQUENCE_CONTAINER_VENEER_MINOR      0
00051 # define STLSOFT_VER_H_STLSOFT_SEQUENCE_CONTAINER_VENEER_REVISION   1
00052 # define STLSOFT_VER_H_STLSOFT_SEQUENCE_CONTAINER_VENEER_EDIT       23
00053 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00054 
00055 /* 
00056  * Compatibility
00057  */
00058 
00059 /*
00060 [Incompatibilies-start]
00061 __STLSOFT_COMPILER_IS_MSVC: _MSC_VER<1200
00062 [Incompatibilies-end]
00063  */
00064 
00065 /* 
00066  * Includes
00067  */
00068 
00069 #ifndef STLSOFT_INCL_H_STLSOFT
00070 # include "stlsoft.h"   // Include the STLSoft root header
00071 #endif /* !STLSOFT_INCL_H_STLSOFT */
00072 
00073 #if defined(__STLSOFT_COMPILER_IS_MSVC) && \
00074     _MSC_VER < 1200
00075 # error stlsoft_sequence_container_veneer.h is not compatible with Visual C++ 5.0 or earlier
00076 #endif /* _MSC_VER < 1200 */
00077 
00078 #ifdef STLSOFT_UNITTEST
00079 # include <algorithm>
00080 # include <list>
00081 # include <vector>
00082 #endif /* STLSOFT_UNITTEST */
00083 
00084 /* 
00085  * Namespace
00086  */
00087 
00088 #ifndef _STLSOFT_NO_NAMESPACE
00089 namespace stlsoft
00090 {
00091 #endif /* _STLSOFT_NO_NAMESPACE */
00092 
00093 /* 
00094  * Classes
00095  */
00096 
00101 template<   ss_typename_param_k T
00102         ,   ss_typename_param_k F
00103         >
00104 class sequence_container_veneer
00105     : public T
00106 {
00107 public:
00109     typedef T                                                       container_type;
00111     typedef F                                                       element_destruction_function_type;
00113     typedef sequence_container_veneer<T, F>                         class_type;
00114 private:
00115     typedef T                                                       parent_class_type;
00116 public:
00118     typedef ss_typename_type_k parent_class_type::allocator_type    allocator_type;
00120     typedef ss_typename_type_k parent_class_type::size_type         size_type;
00121 
00122 // Construction
00123 public:
00124 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00125 
00126     sequence_container_veneer()
00127     {}
00128 
00130     sequence_container_veneer(class_type const &rhs)
00131         : parent_class_type(rhs)
00132     {}
00133 
00134 #if !defined(__STLSOFT_COMPILER_IS_DMC)
00135 
00136     ss_explicit_k sequence_container_veneer(allocator_type const &a)
00137         : parent_class_type(a)
00138     {}
00140     template <ss_typename_param_k I>
00141     sequence_container_veneer(I i1, I i2)
00142         : parent_class_type(i1, i2)
00143     {}
00145     template <ss_typename_param_k I>
00146     sequence_container_veneer(I i1, I i2, allocator_type const &a)
00147         : parent_class_type(i1, i2, a)
00148     {}
00150     template <ss_typename_param_k V>
00151     sequence_container_veneer(size_type n, V v)
00152         : parent_class_type(n, v)
00153     {}
00155     template <ss_typename_param_k V>
00156     sequence_container_veneer(size_type n, V v, allocator_type const &a)
00157         : parent_class_type(n, v, a)
00158     {}
00159 #else
00160     template <ss_typename_param_k N1>
00161     ss_explicit_k sequence_container_veneer(N1 n1)
00162         : parent_class_type(n1)
00163     {}
00164     template<   ss_typename_param_k N1
00165             ,   ss_typename_param_k N2
00166             >
00167     sequence_container_veneer(N1 n1, N2 n2)
00168         : parent_class_type(n1, n2)
00169     {}
00170     template<   ss_typename_param_k N1
00171             ,   ss_typename_param_k N2
00172             ,   ss_typename_param_k N3
00173             >
00174     sequence_container_veneer(N1 n1, N2 n2, N3 n3)
00175         : parent_class_type(n1, n2, n3)
00176     {}
00177     template<   ss_typename_param_k N1
00178             ,   ss_typename_param_k N2
00179             ,   ss_typename_param_k N3
00180             ,   ss_typename_param_k N4
00181             >
00182     sequence_container_veneer(N1 n1, N2 n2, N3 n3, N4 n4)
00183         : parent_class_type(n1, n2, n3, n4)
00184     {}
00185     template<   ss_typename_param_k N1
00186             ,   ss_typename_param_k N2
00187             ,   ss_typename_param_k N3
00188             ,   ss_typename_param_k N4
00189             ,   ss_typename_param_k N5
00190             >
00191     sequence_container_veneer(N1 n1, N2 n2, N3 n3, N4 n4, N5 n5)
00192         : parent_class_type(n1, n2, n3, n4, n5)
00193     {}
00194 #endif /* !__STLSOFT_COMPILER_IS_DMC */
00195 #endif /* !__STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
00196 
00199     ~sequence_container_veneer() stlsoft_throw_0()
00200     {
00201         // Simply iterate through the sequence contents and call
00202         // the destruction function on each item in turn.
00203         parent_class_type                           *this_  =   this;
00204 
00205         ss_typename_type_k container_type::iterator b       =   this_->begin();
00206         ss_typename_type_k container_type::iterator e       =   this_->end();
00207 
00208         for(; b != e; ++b)
00209         {
00210             element_destruction_function_type()(*b);
00211         }
00212     }
00213 
00220     class_type &operator =(class_type const &rhs)
00221     {
00222         parent_class_type::operator =(rhs);
00223 
00224         return *this;
00225     }
00226 
00227 protected:
00230     void *operator new(size_t )
00231     {
00232         return 0;
00233     }
00236     void operator delete(void *)
00237     {}
00238 };
00239 
00241 // Unit-testing
00242 
00243 #ifdef STLSOFT_UNITTEST
00244 
00245 namespace unittest
00246 {
00247 # if !defined(__STLSOFT_COMPILER_IS_MSVC) || \
00248      _MSC_VER >= 1200
00249     namespace
00250     {
00251 #endif /* compiler */
00252         struct null_int_functor
00253         {
00254         public:
00255             void operator ()(int const &)
00256             {}
00257         };
00258 # if !defined(__STLSOFT_COMPILER_IS_MSVC) || \
00259      _MSC_VER >= 1200
00260     } // namespace
00261 #endif /* compiler */
00262 
00263     ss_bool_t test_stlsoft_sequence_container_veneer(unittest_reporter *r)
00264     {
00265         ss_bool_t               bSuccess    =   true;
00266 
00267         unittest_initialiser    init(r, "STLSoft", "sequence_container_veneer", __FILE__);
00268 
00269         typedef stlsoft_ns_qual_std(list)<int>      list_t;
00270         typedef stlsoft_ns_qual_std(vector)<int>    vector_t;
00271 
00272         sequence_container_veneer<list_t, null_int_functor>     l;
00273         sequence_container_veneer<vector_t, null_int_functor>   v;
00274         int                                                     i;
00275         int                                                     total;
00276 
00277         for(i = 0, total = 0; i < 10; ++i)
00278         {
00279             l.push_front(i);
00280             v.push_back(i);
00281 
00282             total += i;
00283         }
00284 
00285         if(stlsoft_ns_qual_std(accumulate)(l.begin(), l.end(), static_cast<long>(0)) != total)
00286         {
00287             r->report("sequence_container_veneer<list> contents (forward iteration) test failed ", __LINE__);
00288             bSuccess = false;
00289         }
00290 
00291 #if defined(__STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00292         if(stlsoft_ns_qual_std(accumulate)(l.rbegin(), l.rend(), static_cast<long>(0)) != total)
00293         {
00294             r->report("sequence_container_veneer<list> contents (forward iteration) test failed ", __LINE__);
00295             bSuccess = false;
00296         }
00297 #endif /* __STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT */
00298 
00299         if(stlsoft_ns_qual_std(accumulate)(v.begin(), v.end(), static_cast<long>(0)) != total)
00300         {
00301             r->report("sequence_container_veneer<vector> contents (forward iteration) test failed ", __LINE__);
00302             bSuccess = false;
00303         }
00304 
00305 #if defined(__STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00306         if(stlsoft_ns_qual_std(accumulate)(v.rbegin(), v.rend(), static_cast<long>(0)) != total)
00307         {
00308             r->report("sequence_container_veneer<vector> contents (forward iteration) test failed ", __LINE__);
00309             bSuccess = false;
00310         }
00311 #endif /* __STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT */
00312 
00313         return bSuccess;
00314     }
00315 
00316     unittest_registrar    unittest_stlsoft_sequence_container_veneer(test_stlsoft_sequence_container_veneer);
00317 
00318 } // namespace unittest
00319 
00320 #endif /* STLSOFT_UNITTEST */
00321 
00322 /* 
00323 
00324 #ifndef _STLSOFT_NO_NAMESPACE
00325 } // namespace stlsoft
00326 #endif /* _STLSOFT_NO_NAMESPACE */
00327 
00328 /* 
00329 
00330 #endif /* !STLSOFT_INCL_H_STLSOFT_SEQUENCE_CONTAINER_VENEER */
00331 
00332 /* 

STLSoft Libraries documentation © Synesis Software Pty Ltd, 2001-2004