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  

winstl_environment_block.h

Go to the documentation of this file.
00001 /* 
00002  * File:        winstl_environment_block.h
00003  *
00004  * Purpose:     Contains the basic_environment_block class.
00005  *
00006  * Created:     25th June 2004
00007  * Updated:     12th September 2004
00008  *
00009  * Home:        http://stlsoft.org/
00010  *
00011  * Copyright (c) 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 WINSTL_INCL_H_WINSTL_ENVIRONMENT_BLOCK
00046 #define WINSTL_INCL_H_WINSTL_ENVIRONMENT_BLOCK
00047 
00048 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00049 # define WINSTL_VER_H_WINSTL_ENVIRONMENT_BLOCK_MAJOR    2
00050 # define WINSTL_VER_H_WINSTL_ENVIRONMENT_BLOCK_MINOR    0
00051 # define WINSTL_VER_H_WINSTL_ENVIRONMENT_BLOCK_REVISION 1
00052 # define WINSTL_VER_H_WINSTL_ENVIRONMENT_BLOCK_EDIT     19
00053 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00054 
00055 /* 
00056  * Compatibility
00057  */
00058 
00059 /* 
00060  * Includes
00061  */
00062 
00063 #ifndef WINSTL_INCL_H_WINSTL
00064 # include "winstl.h"                        // Include the WinSTL root header
00065 #endif /* !WINSTL_INCL_H_WINSTL */
00066 #ifndef WINSTL_INCL_H_WINSTL_PROCESSHEAP_ALLOCATOR
00067 # include "winstl_processheap_allocator.h"  // processheap_allocator
00068 #endif /* !WINSTL_INCL_H_WINSTL_PROCESSHEAP_ALLOCATOR */
00069 #ifndef STLSOFT_INCL_H_STLSOFT_CHAR_TRAITS
00070 # include "stlsoft_char_traits.h"           // char_traits
00071 #endif /* !STLSOFT_INCL_H_STLSOFT_CHAR_TRAITS */
00072 #ifndef WINSTL_INCL_H_WINSTL_STRING_ACCESS
00073 # include "winstl_string_access.h"          // c_str_ptr
00074 #endif /* !WINSTL_INCL_H_WINSTL_STRING_ACCESS */
00075 
00076 /* 
00077  * Namespace
00078  */
00079 
00080 #ifndef _WINSTL_NO_NAMESPACE
00081 # if defined(_STLSOFT_NO_NAMESPACE) || \
00082      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00083 /* There is no stlsoft namespace, so must define ::winstl */
00084 namespace winstl
00085 {
00086 # else
00087 /* Define stlsoft::winstl_project */
00088 
00089 namespace stlsoft
00090 {
00091 
00092 namespace winstl_project
00093 {
00094 
00095 # endif /* _STLSOFT_NO_NAMESPACE */
00096 #endif /* !_WINSTL_NO_NAMESPACE */
00097 
00098 /* 
00099 
00102 
00106 
00111 
00112 /* 
00113  * Classes
00114  */
00115 
00117 template<   ss_typename_param_k C
00118 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00119         ,   ss_typename_param_k T = char_traits<C>
00120         ,   ss_typename_param_k A = processheap_allocator<C>
00121 #else /* ? __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
00122         ,   ss_typename_param_k T /* = char_traits<C> */
00123         ,   ss_typename_param_k A /* = processheap_allocator<C> */
00124 #endif /* __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
00125         >
00126 class basic_environment_block
00127 {
00130 public:
00132     typedef C                                   value_type;
00134     typedef C                                   char_type;
00136     typedef T                                   traits_type;
00138     typedef A                                   allocator_type;
00140     typedef basic_environment_block<C, T, A>    class_type;
00142     typedef ws_size_t                           size_type;
00144 
00147 public:
00148     basic_environment_block()
00149         : m_buffer(2)
00150     {
00151         m_buffer[0] = '\0';
00152         m_buffer[1] = '\0';
00153     }
00154     basic_environment_block(class_type const &rhs)
00155         : m_buffer(rhs.m_buffer.size())
00156     {
00157         pod_copy_n(&m_buffer.data()[0], &rhs.m_buffer.data()[0], m_buffer.size());
00158     }
00159 
00160     class_type &operator =(class_type const &rhs)
00161     {
00162         if(m_buffer.resize(rhs.m_buffer.size()))
00163         {
00164             pod_copy_n(&m_buffer.data()[0], &rhs.m_buffer.data()[0], m_buffer.size());
00165         }
00166 
00167         return *this;
00168     }
00170 
00173 public:
00175     void push_back(char_type const *s, size_t cch)
00176     {
00177         stlsoft_assert(NULL != s);
00178         stlsoft_assert(cch >= 3);
00179         stlsoft_assert(NULL != traits_type::find(s, cch, '='));
00180 
00181         size_type   oldSize = m_buffer.size();
00182 
00183         stlsoft_assert(m_buffer.size() > 1);
00184         stlsoft_assert('\0' == m_buffer[m_buffer.size() - 1]);
00185         stlsoft_assert('\0' == m_buffer[m_buffer.size() - 2]);
00186 
00187         m_buffer.resize(oldSize + cch + 1);
00188 
00189         traits_type::copy(&m_buffer[oldSize - 1], s, cch);
00190         m_buffer[m_buffer.size() - 2] = '\0';
00191         m_buffer[m_buffer.size() - 1] = '\0';
00192 
00193         stlsoft_assert(m_buffer.size() > 1);
00194         stlsoft_assert('\0' == m_buffer[m_buffer.size() - 1]);
00195         stlsoft_assert('\0' == m_buffer[m_buffer.size() - 2]);
00196     }
00197     template <typename S>
00198     void push_back(S const &s)
00199     {
00200         push_back(stlsoft_ns_qual(c_str_ptr)(s), stlsoft_ns_qual(c_str_len)(s));
00201     }
00202     void push_back(char_type const *name, size_t cchName, char_type const *value, size_t cchValue)
00203     {
00204         stlsoft_assert(NULL != name);
00205         stlsoft_assert(NULL != value);
00206         stlsoft_assert(cchName > 1);
00207         stlsoft_assert(cchValue > 1);
00208 
00209         size_type   oldSize = m_buffer.size();
00210 
00211         stlsoft_assert(m_buffer.size() > 1);
00212         stlsoft_assert('\0' == m_buffer[m_buffer.size() - 1]);
00213         stlsoft_assert('\0' == m_buffer[m_buffer.size() - 2]);
00214 
00215         m_buffer.resize(oldSize + cchName + 1 + cchValue + 1);
00216 
00217         traits_type::copy(&m_buffer[oldSize - 2], name, cchName);
00218         m_buffer[oldSize - 2 + cchName] = '=';
00219         traits_type::copy(&m_buffer[oldSize - 2 + cchName + 1], value, cchValue);
00220         m_buffer[oldSize - 2 + cchName + 1 + cchValue] = '\0';
00221         m_buffer[m_buffer.size() - 2] = '\0';
00222         m_buffer[m_buffer.size() - 1] = '\0';
00223 
00224         stlsoft_assert(m_buffer.size() > 1);
00225         stlsoft_assert('\0' == m_buffer[m_buffer.size() - 1]);
00226         stlsoft_assert('\0' == m_buffer[m_buffer.size() - 2]);
00227     }
00228     template <typename S1, typename S2>
00229     void push_back(S1 const &name, S2 const &value)
00230     {
00231         push_back(stlsoft_ns_qual(c_str_ptr)(name), stlsoft_ns_qual(c_str_len)(name), stlsoft_ns_qual(c_str_ptr)(value), stlsoft_ns_qual(c_str_len)(value));
00232     }
00233 
00234     void clear()
00235     {
00236         m_buffer.resize(2);
00237 
00238         m_buffer[0] = '\0';
00239         m_buffer[1] = '\0';
00240     }
00242 
00245 public:
00246     void const  *base() const
00247     {
00248         return m_buffer.data();
00249     }
00250     size_type length() const
00251     {
00252         return m_buffer.size();
00253     }
00255 
00257 private:
00258     typedef stlsoft_ns_qual(auto_buffer)<char_type, allocator_type, 1024>   buffer_type;
00259 
00260     buffer_type m_buffer;
00261 };
00262 
00263 /* 
00264  * Typedefs for commonly encountered types
00265  */
00266 
00267 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00268 
00270 typedef basic_environment_block<ws_char_a_t>    environment_block_a;
00272 typedef basic_environment_block<ws_char_w_t>    environment_block_w;
00274 typedef basic_environment_block<TCHAR>          environment_block;
00275 
00276 #endif /* __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
00277 
00278 /* 
00279  * Unit-testing
00280  */
00281 
00282 #ifdef STLSOFT_UNITTEST
00283 
00284 namespace unittest
00285 {
00286     ss_bool_t test_winstl_environment_block(unittest_reporter *r)
00287     {
00288         using stlsoft::unittest::unittest_initialiser;
00289 
00290         ss_bool_t               bSuccess    =   true;
00291 
00292         unittest_initialiser    init(r, "WinSTL", "environment_block", __FILE__);
00293 
00294         return bSuccess;
00295     }
00296 
00297     unittest_registrar    unittest_winstl_environment_block(test_winstl_environment_block);
00298 
00299 } // namespace unittest
00300 
00301 #endif /* STLSOFT_UNITTEST */
00302 
00303 /* 
00304  * Implementation
00305  */
00306 
00307 /* 
00308 
00310 
00311 /* 
00312 
00313 #ifndef _WINSTL_NO_NAMESPACE
00314 # if defined(_STLSOFT_NO_NAMESPACE) || \
00315      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00316 } // namespace winstl
00317 # else
00318 } // namespace winstl_project
00319 } // namespace stlsoft
00320 # endif /* _STLSOFT_NO_NAMESPACE */
00321 #endif /* !_WINSTL_NO_NAMESPACE */
00322 
00323 /* 
00324 
00325 #endif /* WINSTL_INCL_H_WINSTL_ENVIRONMENT_BLOCK */
00326 
00327 /* 

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