Synesis Software STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ...

pantheios/inserters/args.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////
00002  * File:        pantheios/inserters/args.hpp
00003  *
00004  * Purpose:     String inserter for argc+argv pairs.
00005  *
00006  * Created:     19th October 2006
00007  * Updated:     5th May 2010
00008  *
00009  * Home:        http://www.pantheios.org/
00010  *
00011  * Copyright (c) 2006-2010, 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
00016  * met:
00017  *
00018  * - Redistributions of source code must retain the above copyright notice,
00019  *   this list of conditions and the following disclaimer.
00020  * - Redistributions in binary form must reproduce the above copyright
00021  *   notice, this list of conditions and the following disclaimer in the
00022  *   documentation and/or other materials provided with the distribution.
00023  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
00024  *   names of any contributors may be used to endorse or promote products
00025  *   derived from this software without specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00028  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00029  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00030  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00031  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00032  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00033  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00034  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00035  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00036  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00037  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038  *
00039  * ////////////////////////////////////////////////////////////////////// */
00040 
00041 
00048 #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_ARGS
00049 #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_ARGS
00050 
00051 /* /////////////////////////////////////////////////////////////////////////
00052  * Version information
00053  */
00054 
00055 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00056 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_ARGS_MAJOR       1
00057 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_ARGS_MINOR       6
00058 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_ARGS_REVISION    4
00059 # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_ARGS_EDIT        28
00060 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00061 
00062 /* /////////////////////////////////////////////////////////////////////////
00063  * Includes
00064  */
00065 
00066 #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
00067 # include <pantheios/pantheios.h>
00068 #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
00069 
00070 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD
00071 # include <stlsoft/shims/access/string/fwd.h>
00072 #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD */
00073 
00074 #include <string>
00075 
00076 /* /////////////////////////////////////////////////////////////////////////
00077  * Namespace
00078  */
00079 
00080 #if !defined(PANTHEIOS_NO_NAMESPACE)
00081 namespace pantheios
00082 {
00083 #endif /* !PANTHEIOS_NO_NAMESPACE */
00084 
00085 /* /////////////////////////////////////////////////////////////////////////
00086  * Inserter classes
00087  */
00088 
00142 class args
00143 {
00146 public:
00147     typedef args    class_type;
00149 
00152 public:
00154     enum format_flags
00155     {
00156             neverQuoteArgs      =   0x0000  
00157         ,   quoteArgsWithSpaces =   0x0001  
00158         ,   alwaysQuoteArgs     =   0x0002  
00159         ,   arg0FileOnly        =   0x0004  
00160     };
00162 
00165 public:
00174     args(int argc, pan_char_t const* const* argv, int flags = quoteArgsWithSpaces, pan_char_t const* separator = PANTHEIOS_LITERAL_STRING(", "));
00175 
00176 #ifdef STLSOFT_COMPILER_IS_BORLAND
00177     args(int argc, pan_char_t** argv, int flags = quoteArgsWithSpaces, pan_char_t const* separator = PANTHEIOS_LITERAL_STRING(", "));
00178 #endif /* STLSOFT_COMPILER_IS_BORLAND */
00179 
00180 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00181     ~args() stlsoft_throw_0();
00182 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00184 
00187 public:
00189     pan_char_t const*   data() const;
00191     pan_char_t const*   c_str() const;
00193     size_t              size() const;
00195 
00198 private:
00199     void construct_() const;
00200     void construct_();
00202 
00205 private:
00206     typedef std::basic_string<pan_char_t> string_type_;
00207 
00208     const int                   m_flags;
00209     const int                   m_argc;
00210     pan_char_t const* const*    m_argv;
00211     const string_type_          m_separator;
00212     string_type_                m_result;
00214 
00217 private:
00218 #if !defined(STLSOFT_COMPILER_IS_GCC)
00219     args(class_type const&);
00220 #endif /* compiler */
00221     class_type& operator =(class_type const&);
00223 };
00224 
00225 /* /////////////////////////////////////////////////////////////////////////
00226  * String Access Shims
00227  */
00228 
00229 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00230 
00231 # if !defined(PANTHEIOS_NO_NAMESPACE)
00232 namespace shims
00233 {
00234 # endif /* !PANTHEIOS_NO_NAMESPACE */
00235 
00237 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00238 inline wchar_t const* c_str_data_w(args const& a)
00239 {
00240     return a.data();
00241 }
00242 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00243 inline char const* c_str_data_a(args const& a)
00244 {
00245     return a.data();
00246 }
00247 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00248 
00249 inline pan_char_t const* c_str_data(args const& a)
00250 {
00251     return a.data();
00252 }
00253 
00255 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00256 inline size_t c_str_len_w(args const& a)
00257 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00258 inline size_t c_str_len_a(args const& a)
00259 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00260 {
00261     return a.size();
00262 }
00264 inline size_t c_str_len(args const& a)
00265 {
00266     return a.size();
00267 }
00268 
00270 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00271 inline wchar_t const* c_str_ptr_w(args const& a)
00272 {
00273     return a.c_str();
00274 }
00275 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00276 inline char const* c_str_ptr_a(args const& a)
00277 {
00278     return a.c_str();
00279 }
00280 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00281 
00282 inline pan_char_t const* c_str_ptr(args const& a)
00283 {
00284     return a.c_str();
00285 }
00286 
00287 # if !defined(PANTHEIOS_NO_NAMESPACE)
00288 } /* namespace shims */
00289 
00290 #  if defined(STLSOFT_COMPILER_IS_GCC)
00291     /* GCC does not seem to correctly handle the phases of
00292      * processing of C++ templates, so we need to 'use' the
00293      * shims into the same namespace as the inserter class
00294      * in order that ADL can suffice instead.
00295      */
00296 #   ifdef PANTHEIOS_USE_WIDE_STRINGS
00297     using ::pantheios::shims::c_str_data_w;
00298     using ::pantheios::shims::c_str_len_w;
00299     using ::pantheios::shims::c_str_ptr_w;
00300 #   else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00301     using ::pantheios::shims::c_str_data_a;
00302     using ::pantheios::shims::c_str_len_a;
00303     using ::pantheios::shims::c_str_ptr_a;
00304 #   endif /* PANTHEIOS_USE_WIDE_STRINGS */
00305     using ::pantheios::shims::c_str_data;
00306     using ::pantheios::shims::c_str_len;
00307     using ::pantheios::shims::c_str_ptr;
00308 #  endif /* compiler */
00309 
00310 # endif /* !PANTHEIOS_NO_NAMESPACE */
00311 
00312 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00313 
00314 /* /////////////////////////////////////////////////////////////////////////
00315  * Namespace
00316  */
00317 
00318 #if !defined(PANTHEIOS_NO_NAMESPACE)
00319 } /* namespace pantheios */
00320 
00321 namespace stlsoft
00322 {
00323     // 'Export' the string access shims into the STLSoft namespace
00324     //
00325     // c_str_ptr(_a) is not necessary for version 1.0 of Pantheios, but it's
00326     // defined and exported in order to allow for the case where someone
00327     // may find a legitimate use for the conversion classes additional to
00328     // the type-tunneling of the Pantheios API.
00329 
00330 # ifdef PANTHEIOS_USE_WIDE_STRINGS
00331     using ::pantheios::shims::c_str_data_w;
00332     using ::pantheios::shims::c_str_len_w;
00333     using ::pantheios::shims::c_str_ptr_w;
00334 # else /* ? PANTHEIOS_USE_WIDE_STRINGS */
00335     using ::pantheios::shims::c_str_data_a;
00336     using ::pantheios::shims::c_str_len_a;
00337     using ::pantheios::shims::c_str_ptr_a;
00338 # endif /* PANTHEIOS_USE_WIDE_STRINGS */
00339     using ::pantheios::shims::c_str_data;
00340     using ::pantheios::shims::c_str_len;
00341     using ::pantheios::shims::c_str_ptr;
00342 }
00343 
00344 #endif /* !PANTHEIOS_NO_NAMESPACE */
00345 
00346 /* /////////////////////////////////////////////////////////////////////////
00347  * Inclusion
00348  */
00349 
00350 #ifdef STLSOFT_PPF_pragma_once_SUPPORT
00351 # pragma once
00352 #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
00353 
00354 /* ////////////////////////////////////////////////////////////////////// */
00355 
00356 #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_ARGS */
00357 
00358 /* ///////////////////////////// end of file //////////////////////////// */

pantheios Library documentation Matthew Wilson & Synesis Software, 2006-2011 SourceForge.net Logo