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

recls/stl/traits.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        recls/stl/traits.hpp
00003  *
00004  * Purpose:     Contains character-base traits for the recls::stl mapping.
00005  *
00006  * Created:     25th March 2004
00007  * Updated:     2nd June 2007
00008  *
00009  * Home:        http://recls.org/
00010  *
00011  * Copyright (c) 2004-2007, 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 
00041 #ifndef RECLS_INCL_RECLSTL_STL_HPP_TRAITS
00042 #define RECLS_INCL_RECLSTL_STL_HPP_TRAITS
00043 
00044 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00045 # define RECLS_VER_RECLSTL_STL_HPP_TRAITS_MAJOR     4
00046 # define RECLS_VER_RECLSTL_STL_HPP_TRAITS_MINOR     0
00047 # define RECLS_VER_RECLSTL_STL_HPP_TRAITS_REVISION  3
00048 # define RECLS_VER_RECLSTL_STL_HPP_TRAITS_EDIT      17
00049 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00050 
00059 /* /////////////////////////////////////////////////////////////////////////////
00060  * Includes
00061  */
00062 
00063 #ifndef RECLS_INCL_RECLS_STL_HPP_RECLS
00064 # include <recls/stl/recls.hpp>
00065 #endif /* !RECLS_INCL_RECLS_STL_HPP_RECLS */
00066 #ifndef RECLS_INCL_H_RECLS_ASSERT
00067 # include <recls/assert.h>
00068 #endif /* !RECLS_INCL_H_RECLS_ASSERT */
00069 #include <stlsoft/obsolete/proxy_sequence.hpp>
00070 
00071 /* /////////////////////////////////////////////////////////////////////////////
00072  * Namespace
00073  */
00074 
00075 #if !defined(RECLS_NO_NAMESPACE)
00076 namespace recls
00077 {
00078 
00079 namespace stl
00080 {
00081 #endif /* !RECLS_NO_NAMESPACE */
00082 
00083 /* /////////////////////////////////////////////////////////////////////////////
00084  * Classes
00085  */
00086 
00090 template <typename C>
00091 struct reclstl_traits
00092 {
00093 public:
00098     typedef void            char_type;
00103     typedef void            *entry_type;
00104 
00105 public:
00106 #if defined(RECLS_API_FTP)
00108     static recls_rc_t       SearchFtp(char_type const *host, char_type const *username, char_type const *password, char_type const *searchRoot, char_type const *pattern, recls_uint32_t flags, hrecls_t *phSrch);
00109 #endif /* RECLS_API_FTP */
00110 
00112     static recls_rc_t       Search(char_type const *searchRoot, char_type const *pattern, recls_uint32_t flags, hrecls_t *phSrch);
00113 
00115     static recls_rc_t       GetDetails(hrecls_t hSrch, entry_type *pinfo);
00117     static recls_rc_t       GetNextDetails(hrecls_t hSrch, entry_type *pinfo);
00118 
00120     static void             CloseDetails(entry_type fileInfo);
00122     static entry_type       CopyDetails(entry_type fileInfo);
00123 
00125     static char_type        *str_copy(char_type *, char_type const *);
00126 };
00127 
00128 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00129 
00130 # ifdef RECLS_CHAR_TYPE_IS_CHAR
00131 
00132 template <>
00133 struct reclstl_traits<recls_char_a_t>
00134 {
00135 public:
00136     typedef reclstl_traits<recls_char_a_t>      traits_type;
00137     typedef recls_char_a_t                      char_type;
00138     typedef recls_info_t                        entry_type;
00139     typedef recls_strptrs_t                     strptrs_type;
00140     typedef recls_strptrsptrs_t                 strptrsptrs_type;
00141 
00143     typedef stlsoft::proxy_sequence<    const strptrs_type
00144                                     ,   string_t
00145                                     ,   traits_type // Note, this type also serves as the traits type for the STLSoft proxy_sequence
00146                                     >           directory_parts_type;
00147 
00151     static string_t make_value(strptrs_type const &ptrs)
00152     {
00153         return string_t(ptrs.begin, ptrs.end);
00154     }
00155 
00156 public:
00157 #if defined(RECLS_API_FTP)
00158     static recls_rc_t SearchFtp(char_type const *host, char_type const *username, char_type const *password, char_type const *searchRoot, char_type const *pattern, recls_uint32_t flags, hrecls_t *phSrch)
00159     {
00160         return Recls_SearchFtp(host, username, password, searchRoot, pattern, flags, phSrch);
00161     }
00162 #endif /* RECLS_API_FTP */
00163 
00164     static recls_rc_t Search(char_type const *searchRoot, char_type const *pattern, recls_uint32_t flags, hrecls_t *phSrch)
00165     {
00166         return Recls_Search(searchRoot, pattern, flags, phSrch);
00167     }
00168 
00169     static recls_rc_t GetDetails(hrecls_t hSrch, entry_type *pinfo)
00170     {
00171         return Recls_GetDetails(hSrch, pinfo);
00172     }
00173 
00174     static recls_rc_t GetNextDetails(hrecls_t hSrch, entry_type *pinfo)
00175     {
00176         return Recls_GetNextDetails(hSrch, pinfo);
00177     }
00178 
00179     static void CloseDetails(entry_type fileInfo)
00180     {
00181         Recls_CloseDetails(fileInfo);
00182     }
00183     static entry_type CopyDetails(entry_type fileInfo)
00184     {
00185         entry_type  infoCopy;
00186 
00187         return RECLS_SUCCEEDED(Recls_CopyDetails(fileInfo, &infoCopy)) ? infoCopy : static_cast<entry_type>(NULL);
00188     }
00189 
00190     static char_type *str_copy(char_type *dest, char_type const *src)
00191     {
00192         return ::strcpy(dest, src);
00193     }
00194 };
00195 
00196 # elif defined(RECLS_CHAR_TYPE_IS_WCHAR)
00197 
00198 template <>
00199 struct reclstl_traits<recls_char_w_t>
00200 {
00201 public:
00202     typedef reclstl_traits<recls_char_w_t>      traits_type;
00203     typedef recls_char_w_t                      char_type;
00204     typedef recls_info_t                        entry_type;
00205     typedef recls_strptrs_t                     strptrs_type;
00206     typedef recls_strptrsptrs_t                 strptrsptrs_type;
00207 
00209     typedef stlsoft::proxy_sequence<    const strptrs_type
00210                                     ,   string_t
00211                                     ,   traits_type // Note, this type also serves as the traits type for the STLSoft proxy_sequence
00212                                     >           directory_parts_type;
00213 
00217     static string_t make_value(strptrs_type const &ptrs)
00218     {
00219         return string_t(ptrs.begin, ptrs.end);
00220     }
00221 
00222 public:
00223 #if defined(RECLS_API_FTP)
00224     static recls_rc_t SearchFtp(char_type const *host, char_type const *username, char_type const *password, char_type const *searchRoot, char_type const *pattern, recls_uint32_t flags, hrecls_t *phSrch)
00225     {
00226         return Recls_SearchFtp(host, username, password, searchRoot, pattern, flags, phSrch);
00227     }
00228 #endif /* RECLS_API_FTP */
00229 
00230     static recls_rc_t Search(char_type const *searchRoot, char_type const *pattern, recls_uint32_t flags, hrecls_t *phSrch)
00231     {
00232         return Recls_Search(searchRoot, pattern, flags, phSrch);
00233     }
00234 
00235     static recls_rc_t GetDetails(hrecls_t hSrch, entry_type *pinfo)
00236     {
00237         return Recls_GetDetails(hSrch, pinfo);
00238     }
00239 
00240     static recls_rc_t GetNextDetails(hrecls_t hSrch, entry_type *pinfo)
00241     {
00242         return Recls_GetNextDetails(hSrch, pinfo);
00243     }
00244 
00245     static void CloseDetails(entry_type fileInfo)
00246     {
00247         Recls_CloseDetails(fileInfo);
00248     }
00249     static entry_type CopyDetails(entry_type fileInfo)
00250     {
00251         entry_type  infoCopy;
00252 
00253         return RECLS_SUCCEEDED(Recls_CopyDetails(fileInfo, &infoCopy)) ? infoCopy : static_cast<entry_type>(NULL);
00254     }
00255 
00256     static char_type *str_copy(char_type *dest, char_type const *src)
00257     {
00258         return wcscpy(dest, src);
00259     }
00260 };
00261 
00262 # else /* character type */
00263 
00264 #  error Neither RECLS_CHAR_TYPE_IS_WCHAR nor RECLS_CHAR_TYPE_IS_CHAR are defined
00265 
00266 # endif /* character type */
00267 
00268 
00269 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00270 
00271 /* ////////////////////////////////////////////////////////////////////////// */
00272 
00273 #if !defined(RECLS_NO_NAMESPACE)
00274 } /* namespace stl */
00275 } /* namespace recls */
00276 #endif /* !RECLS_NO_NAMESPACE */
00277 
00278 /* ////////////////////////////////////////////////////////////////////////// */
00279 
00280 #endif /* RECLS_INCL_RECLSTL_STL_HPP_TRAITS */
00281 
00282 /* ////////////////////////////////////////////////////////////////////////// */

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