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/cpp/search.hpp

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        recls/cpp/search.hpp
00003  *
00004  * Purpose:     recls C++ mapping - Search class.
00005  *
00006  * Created:     18th August 2003
00007  * Updated:     16th June 2006
00008  *
00009  * Home:        http://recls.org/
00010  *
00011  * Copyright (c) 2003-2006, 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_RECLS_CPP_HPP_SEARCH
00042 #define RECLS_INCL_RECLS_CPP_HPP_SEARCH
00043 
00044 /* File version */
00045 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00046 # define RECLS_VER_RECLS_CPP_HPP_SEARCH_MAJOR       3
00047 # define RECLS_VER_RECLS_CPP_HPP_SEARCH_MINOR       0
00048 # define RECLS_VER_RECLS_CPP_HPP_SEARCH_REVISION    2
00049 # define RECLS_VER_RECLS_CPP_HPP_SEARCH_EDIT        11
00050 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00051 
00060 /* /////////////////////////////////////////////////////////////////////////////
00061  * Includes
00062  */
00063 
00064 #include <recls/cpp/recls.hpp>      // reclspp root header
00065 #include <recls/cpp/fileentry.hpp>  // reclspp::FileEntry
00066 #include <recls/assert.h>           // RECLS_ASSERT
00067 #include <utility>                  // pair
00068 
00069 /* /////////////////////////////////////////////////////////////////////////////
00070  * Namespace
00071  */
00072 
00073 #if !defined(RECLS_NO_NAMESPACE)
00074 namespace recls
00075 {
00076 
00077 namespace cpp
00078 {
00079 #endif /* !RECLS_NO_NAMESPACE */
00080 
00081 /* /////////////////////////////////////////////////////////////////////////////
00082  * Classes
00083  */
00084 
00088 class Search
00089 {
00091 public:
00093     typedef Search      class_type;
00095 
00098 protected:
00099     typedef std::pair<hrecls_t, recls_rc_t> ctor_args_type;
00100 
00104     Search(ctor_args_type args);
00105 public:
00111     virtual ~Search() = 0;
00113 
00116 public:
00118     recls_rc_t      GetNext();
00120 
00123 public:
00125     recls_bool_t    HasMoreElements() const;
00129     FileEntry       GetCurrentEntry() const;
00130 
00132     recls_rc_t      GetLastError() const;
00133 
00135     recls_uint32_t  GetNumOutstandingDetails() const;
00137 
00138 // Implementation
00139 protected:
00140     // This method is needed because there is no way to call a function in the 
00141     // MIL of a derived class and pass more than one argument to a base ctor
00142     recls_rc_t          &GetLastError_();
00143 
00144     static FileEntry    make_entry_(recls_info_t info);
00145 
00146 // Members
00147 private:
00148     hrecls_t /* const */    m_hSrch;
00149     mutable recls_rc_t      m_lastError;
00150 
00151 // Not to be implemented
00152 private:
00153     Search(class_type const &);
00154     class_type &operator =(class_type const &);
00155 };
00156 
00157 /* /////////////////////////////////////////////////////////////////////////////
00158  * Implementation
00159  */
00160 
00161 inline /* static */ FileEntry   Search::make_entry_(recls_info_t info)
00162 {
00163     return FileEntry(info);
00164 }
00165 
00166 
00167 inline Search::Search(Search::ctor_args_type args)
00168     : m_hSrch(args.first)
00169     , m_lastError(args.second)
00170 {
00171     RECLS_ASSERT(NULL != m_hSrch || RECLS_FAILED(m_lastError));
00172     RECLS_ASSERT(NULL == m_hSrch || RECLS_SUCCEEDED(m_lastError));
00173 }
00174 
00175 inline Search::~Search()
00176 {
00177     if(NULL != m_hSrch)
00178     {
00179         Recls_SearchClose(m_hSrch);
00180     }
00181 }
00182 
00183 inline recls_rc_t Search::GetNext()
00184 {
00185     RECLS_ASSERT(NULL != m_hSrch);
00186 
00187     recls_rc_t  rc  =   Recls_GetNext(m_hSrch);
00188 
00189     if(RECLS_FAILED(rc))
00190     {
00191         Recls_SearchClose(m_hSrch);
00192         m_hSrch = NULL;
00193     }
00194 
00195     m_lastError = rc;
00196 
00197     return rc;
00198 }
00199 
00200 inline recls_bool_t Search::HasMoreElements() const
00201 {
00202     return RECLS_SUCCEEDED(m_lastError);
00203 }
00204 
00205 inline FileEntry Search::GetCurrentEntry() const
00206 {
00207     recls_info_t    info;
00208     recls_rc_t      rc  =   Recls_GetDetails(m_hSrch, &info);
00209 
00210     return RECLS_SUCCEEDED(m_lastError = rc) ? make_entry_(info) : FileEntry();
00211 }
00212 
00213 inline recls_rc_t Search::GetLastError() const
00214 {
00215     return m_lastError;
00216 }
00217 
00218 inline recls_uint32_t Search::GetNumOutstandingDetails() const
00219 {
00220     recls_uint32_t  cDetails;
00221     recls_rc_t      rc  =   Recls_OutstandingDetails(m_hSrch, &cDetails);
00222 
00223     if(RECLS_FAILED(m_lastError = rc))
00224     {
00225         cDetails = 0;
00226     }
00227 
00228     return cDetails;
00229 }
00230 
00231 inline recls_rc_t &Search::GetLastError_()
00232 {
00233     return m_lastError;
00234 }
00235 
00236 /* /////////////////////////////////////////////////////////////////////////////
00237  * Namespace
00238  */
00239 
00240 #if !defined(RECLS_NO_NAMESPACE)
00241 } /* namespace cpp */
00242 } /* namespace recls */
00243 #endif /* !RECLS_NO_NAMESPACE */
00244 
00245 /* ////////////////////////////////////////////////////////////////////////// */
00246 
00247 #endif /* !RECLS_INCL_RECLS_CPP_HPP_SEARCH */
00248 
00249 /* ////////////////////////////////////////////////////////////////////////// */

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