C/C++ User's Journal Synesis Software 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 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  

/Mappings/Cpp/reclspp_search.h

Go to the documentation of this file.
00001 /* 
00002  * File:        reclspp_search.h
00003  *
00004  * Purpose:     recls C++ mapping - Search class.
00005  *
00006  * Created:     18th August 2003
00007  * Updated:     6th June 2004
00008  *
00009  * Author:      Matthew Wilson, Synesis Software Pty Ltd.
00010  *
00011  * License:     (Licensed under the Synesis Software Standard Source License)
00012  *
00013  *              Copyright (C) 2002-2004, Synesis Software Pty Ltd.
00014  *
00015  *              All rights reserved.
00016  *
00017  *              www:        http://www.synesis.com.au/software
00018  *                          http://www.recls.org/
00019  *
00020  *              email:      submissions@recls.org  for submissions
00021  *                          admin@recls.org        for other enquiries
00022  *
00023  *              Redistribution and use in source and binary forms, with or
00024  *              without modification, are permitted provided that the following
00025  *              conditions are met:
00026  *
00027  *              (i) Redistributions of source code must retain the above
00028  *              copyright notice and contact information, this list of
00029  *              conditions and the following disclaimer.
00030  *
00031  *              (ii) Any derived versions of this software (howsoever modified)
00032  *              remain the sole property of Synesis Software.
00033  *
00034  *              (iii) Any derived versions of this software (howsoever modified)
00035  *              remain subject to all these conditions.
00036  *
00037  *              (iv) Neither the name of Synesis Software nor the names of any
00038  *              subdivisions, employees or agents of Synesis Software, nor the
00039  *              names of any other contributors to this software may be used to
00040  *              endorse or promote products derived from this software without
00041  *              specific prior written permission.
00042  *
00043  *              This source code is provided by Synesis Software "as is" and any
00044  *              warranties, whether expressed or implied, including, but not
00045  *              limited to, the implied warranties of merchantability and
00046  *              fitness for a particular purpose are disclaimed. In no event
00047  *              shall the Synesis Software be liable for any direct, indirect,
00048  *              incidental, special, exemplary, or consequential damages
00049  *              (including, but not limited to, procurement of substitute goods
00050  *              or services; loss of use, data, or profits; or business
00051  *              interruption) however caused and on any theory of liability,
00052  *              whether in contract, strict liability, or tort (including
00053  *              negligence or otherwise) arising in any way out of the use of
00054  *              this software, even if advised of the possibility of such
00055  *              damage.
00056  *
00057  * 
00058 
00059 
00060 #ifndef RECLS_INCL_H_RECLSPP_SEARCH
00061 #define RECLS_INCL_H_RECLSPP_SEARCH
00062 
00063 /* File version */
00064 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00065 # define RECLS_VER_H_RECLSPP_SEARCH_MAJOR       1
00066 # define RECLS_VER_H_RECLSPP_SEARCH_MINOR       0
00067 # define RECLS_VER_H_RECLSPP_SEARCH_REVISION    2
00068 # define RECLS_VER_H_RECLSPP_SEARCH_EDIT        2
00069 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00070 
00075 /* 
00076  * Includes
00077  */
00078 
00079 #include "reclspp.h"                    // reclspp root header
00080 #include "reclspp_fileentry.h"  // reclspp::FileEntry
00081 #include <recls_assert.h>               // recls_assert
00082 #include <utility>                              // pair
00083 
00084 /* 
00085  * Namespace
00086  */
00087 
00088 #if !defined(RECLS_NO_NAMESPACE)
00089 namespace recls
00090 {
00091 
00092 namespace cpp
00093 {
00094 #endif /* !RECLS_NO_NAMESPACE */
00095 
00096 /* 
00097  * Classes
00098  */
00099 
00103 class Search
00104 {
00106 public:
00108         typedef Search          class_type;
00110 
00113 protected:
00114         typedef std::pair<hrecls_t, recls_rc_t> ctor_args_type;
00115 
00119     Search(ctor_args_type args);
00120 public:
00126     virtual ~Search() = 0;
00128 
00131 public:
00133     recls_rc_t      GetNext();
00135 
00138 public:
00140     recls_bool_t    HasMoreElements() const;
00144     FileEntry       GetCurrentEntry() const;
00145 
00147     recls_rc_t      GetLastError() const;
00148 
00150     recls_uint32_t  GetNumOutstandingDetails() const;
00152 
00153 // Implementation
00154 protected:
00155         // This method is needed because there is no way to call a function in the 
00156         // MIL of a derived class and pass more than one argument to a base ctor
00157         recls_rc_t              &GetLastError_();
00158 
00159 // Members
00160 private:
00161     hrecls_t /* const */    m_hSrch;
00162     mutable recls_rc_t      m_lastError;
00163 
00164 // Not to be implemented
00165 private:
00166     Search(class_type const &);
00167     class_type &operator =(class_type const &);
00168 };
00169 
00170 /* 
00171  * Implementation
00172  */
00173 
00174 inline Search::Search(Search::ctor_args_type args)
00175         : m_hSrch(args.first)
00176         , m_lastError(args.second)
00177 {
00178         recls_assert(NULL != m_hSrch || RECLS_FAILED(m_lastError));
00179         recls_assert(NULL == m_hSrch || RECLS_SUCCEEDED(m_lastError));
00180 }
00181 
00182 inline Search::~Search()
00183 {
00184     if(NULL != m_hSrch)
00185     {
00186         Recls_SearchClose(m_hSrch);
00187     }
00188 }
00189 
00190 inline recls_rc_t Search::GetNext()
00191 {
00192     recls_assert(NULL != m_hSrch);
00193 
00194     recls_rc_t  rc  =   Recls_GetNext(m_hSrch);
00195 
00196     if(RECLS_FAILED(rc))
00197     {
00198         Recls_SearchClose(m_hSrch);
00199         m_hSrch = NULL;
00200     }
00201 
00202     m_lastError = rc;
00203 
00204     return rc;
00205 }
00206 
00207 inline recls_bool_t Search::HasMoreElements() const
00208 {
00209     return RECLS_SUCCEEDED(m_lastError);
00210 }
00211 
00212 inline FileEntry Search::GetCurrentEntry() const
00213 {
00214     recls_info_t    info;
00215     recls_rc_t      rc  =   Recls_GetDetails(m_hSrch, &info);
00216 
00217     return RECLS_SUCCEEDED(m_lastError = rc) ? FileEntry(info) : FileEntry();
00218 }
00219 
00220 inline recls_rc_t Search::GetLastError() const
00221 {
00222     return m_lastError;
00223 }
00224 
00225 inline recls_uint32_t Search::GetNumOutstandingDetails() const
00226 {
00227     recls_uint32_t  cDetails;
00228     recls_rc_t      rc  =   Recls_OutstandingDetails(m_hSrch, &cDetails);
00229 
00230     if(RECLS_FAILED(m_lastError = rc))
00231     {
00232         cDetails = 0;
00233     }
00234 
00235     return cDetails;
00236 }
00237 
00238 inline recls_rc_t &Search::GetLastError_()
00239 {
00240     return m_lastError;
00241 }
00242 
00243 /* 
00244  * Namespace
00245  */
00246 
00247 #if !defined(RECLS_NO_NAMESPACE)
00248 } /* namespace cpp */
00249 } /* namespace recls */
00250 #endif /* !RECLS_NO_NAMESPACE */
00251 
00252 /* 
00253 
00254 #endif /* !RECLS_INCL_H_RECLSPP_SEARCH */
00255 
00256 /* 

recls Library documentation Synesis Software Pty Ltd, 2001-2004