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

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

/include/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:     15th March 2005
00008  *
00009  * Home:        http://recls.org/
00010  *
00011  * Copyright 2003-2005, 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       2
00047 # define RECLS_VER_RECLS_CPP_HPP_SEARCH_MINOR       2
00048 # define RECLS_VER_RECLS_CPP_HPP_SEARCH_REVISION    1
00049 # define RECLS_VER_RECLS_CPP_HPP_SEARCH_EDIT        7
00050 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00051 
00056 /* 
00057  * Includes
00058  */
00059 
00060 #include <recls/cpp/recls.hpp>      // reclspp root header
00061 #include <recls/cpp/fileentry.hpp>  // reclspp::FileEntry
00062 #include <recls_assert.h>           // recls_assert
00063 #include <utility>                  // pair
00064 
00065 /* 
00066  * Namespace
00067  */
00068 
00069 #if !defined(RECLS_NO_NAMESPACE)
00070 namespace recls
00071 {
00072 
00073 namespace cpp
00074 {
00075 #endif /* !RECLS_NO_NAMESPACE */
00076 
00077 /* 
00078  * Classes
00079  */
00080 
00084 class Search
00085 {
00087 public:
00089     typedef Search      class_type;
00091 
00094 protected:
00095     typedef std::pair<hrecls_t, recls_rc_t> ctor_args_type;
00096 
00100     Search(ctor_args_type args);
00101 public:
00107     virtual ~Search() = 0;
00109 
00112 public:
00114     recls_rc_t      GetNext();
00116 
00119 public:
00121     recls_bool_t    HasMoreElements() const;
00125     FileEntry       GetCurrentEntry() const;
00126 
00128     recls_rc_t      GetLastError() const;
00129 
00131     recls_uint32_t  GetNumOutstandingDetails() const;
00133 
00134 // Implementation
00135 protected:
00136     // This method is needed because there is no way to call a function in the 
00137     // MIL of a derived class and pass more than one argument to a base ctor
00138     recls_rc_t          &GetLastError_();
00139 
00140     static FileEntry    make_entry_(recls_info_t info);
00141 
00142 // Members
00143 private:
00144     hrecls_t /* const */    m_hSrch;
00145     mutable recls_rc_t      m_lastError;
00146 
00147 // Not to be implemented
00148 private:
00149     Search(class_type const &);
00150     class_type &operator =(class_type const &);
00151 };
00152 
00153 /* 
00154  * Implementation
00155  */
00156 
00157 inline /* static */ FileEntry   Search::make_entry_(recls_info_t info)
00158 {
00159     return FileEntry(info);
00160 }
00161 
00162 
00163 inline Search::Search(Search::ctor_args_type args)
00164     : m_hSrch(args.first)
00165     , m_lastError(args.second)
00166 {
00167     recls_assert(NULL != m_hSrch || RECLS_FAILED(m_lastError));
00168     recls_assert(NULL == m_hSrch || RECLS_SUCCEEDED(m_lastError));
00169 }
00170 
00171 inline Search::~Search()
00172 {
00173     if(NULL != m_hSrch)
00174     {
00175         Recls_SearchClose(m_hSrch);
00176     }
00177 }
00178 
00179 inline recls_rc_t Search::GetNext()
00180 {
00181     recls_assert(NULL != m_hSrch);
00182 
00183     recls_rc_t  rc  =   Recls_GetNext(m_hSrch);
00184 
00185     if(RECLS_FAILED(rc))
00186     {
00187         Recls_SearchClose(m_hSrch);
00188         m_hSrch = NULL;
00189     }
00190 
00191     m_lastError = rc;
00192 
00193     return rc;
00194 }
00195 
00196 inline recls_bool_t Search::HasMoreElements() const
00197 {
00198     return RECLS_SUCCEEDED(m_lastError);
00199 }
00200 
00201 inline FileEntry Search::GetCurrentEntry() const
00202 {
00203     recls_info_t    info;
00204     recls_rc_t      rc  =   Recls_GetDetails(m_hSrch, &info);
00205 
00206     return RECLS_SUCCEEDED(m_lastError = rc) ? make_entry_(info) : FileEntry();
00207 }
00208 
00209 inline recls_rc_t Search::GetLastError() const
00210 {
00211     return m_lastError;
00212 }
00213 
00214 inline recls_uint32_t Search::GetNumOutstandingDetails() const
00215 {
00216     recls_uint32_t  cDetails;
00217     recls_rc_t      rc  =   Recls_OutstandingDetails(m_hSrch, &cDetails);
00218 
00219     if(RECLS_FAILED(m_lastError = rc))
00220     {
00221         cDetails = 0;
00222     }
00223 
00224     return cDetails;
00225 }
00226 
00227 inline recls_rc_t &Search::GetLastError_()
00228 {
00229     return m_lastError;
00230 }
00231 
00232 /* 
00233  * Namespace
00234  */
00235 
00236 #if !defined(RECLS_NO_NAMESPACE)
00237 } /* namespace cpp */
00238 } /* namespace recls */
00239 #endif /* !RECLS_NO_NAMESPACE */
00240 
00241 /* 
00242 
00243 #endif /* !RECLS_INCL_RECLS_CPP_HPP_SEARCH */
00244 
00245 /* 

recls Library documentation Synesis Software Pty Ltd, 2001-2005