00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00048 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_OPTIONS_VERIFIER
00049 #define STLSOFT_INCL_STLSOFT_UTIL_HPP_OPTIONS_VERIFIER
00050 
00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00052 # define STLSOFT_VER_STLSOFT_UTIL_HPP_OPTIONS_VERIFIER_MAJOR     2
00053 # define STLSOFT_VER_STLSOFT_UTIL_HPP_OPTIONS_VERIFIER_MINOR     0
00054 # define STLSOFT_VER_STLSOFT_UTIL_HPP_OPTIONS_VERIFIER_REVISION  4
00055 # define STLSOFT_VER_STLSOFT_UTIL_HPP_OPTIONS_VERIFIER_EDIT      43
00056 #endif 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 #if defined(STLSOFT_COMPILER_IS_MWERKS) || \
00069     (   defined(STLSOFT_COMPILER_IS_MSVC) && \
00070         _MSC_VER == 1200)
00071 # define STLSOFT_OPTIONS_VERIFIER_REQUIRES_SEPARATE_NS
00072 #endif 
00073 
00074 
00075 
00076 
00077 
00078 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00079 # include <stlsoft/stlsoft.h>
00080 #endif 
00081 #if defined(STLSOFT_COMPILER_IS_MSVC) && \
00082     _MSC_VER == 1300
00083 # pragma warning("Inclusion of this header can lead to ambiguities with the sequence operator (comma) with Visual C++ 7.0")
00084 #endif 
00085 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
00086 # include <stlsoft/shims/access/string.hpp>
00087 #endif 
00088 
00089 #ifndef STLSOFT_INCL_EXCEPTION
00090 # define STLSOFT_INCL_EXCEPTION
00091 # include <exception>                    
00092 #endif 
00093 #ifndef STLSOFT_INCL_STDEXCEPT
00094 # define STLSOFT_INCL_STDEXCEPT
00095 # include <stdexcept>                    
00096 #endif 
00097 
00098 #ifdef STLSOFT_UNITTEST
00099 # include <string>
00100 #endif 
00101 
00102 
00103 
00104 
00105 
00106 #ifndef _STLSOFT_NO_NAMESPACE
00107 namespace stlsoft
00108 {
00109 #endif 
00110 
00111 
00112 
00113 
00114 
00120 class option_verification_exception
00121     : public stlsoft_ns_qual_std(runtime_error)
00122 {
00123 public:
00124     typedef stlsoft_ns_qual_std(runtime_error)  parent_class_type;
00125     typedef option_verification_exception       class_type;
00126 
00127 public:
00128     option_verification_exception(char const* message)
00129         : parent_class_type(message)
00130     {}
00131 #ifdef STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00132     template <ss_typename_param_k S>
00133     option_verification_exception(S const& message)
00134         : parent_class_type(stlsoft_ns_qual(c_str_ptr)(message))
00135     {}
00136 #endif 
00140     option_verification_exception(class_type const& rhs)
00141         : parent_class_type(rhs)
00142     {}
00143 
00147     class_type& operator =(class_type const& rhs)
00148     {
00149         parent_class_type::operator =(rhs);
00150 
00151         return *this;
00152     }
00153 };
00154 
00160 
00161 struct option_verification_policy
00162 {
00163 public:
00165     typedef option_verification_exception   thrown_type;
00166 
00167 public:
00168     void operator ()(char const* message)
00169     {
00170         STLSOFT_THROW_X(option_verification_exception(message));
00171     }
00172 };
00173 
00174 #ifdef STLSOFT_OPTIONS_VERIFIER_REQUIRES_SEPARATE_NS
00175 namespace options_verifier_internal_ns
00176 {
00177 #endif 
00178 
00179 
00185 template<   ss_typename_param_k T
00186         ,   ss_typename_param_k XP  =   option_verification_policy
00187         >
00188 class options_verifier
00189 #if !defined(STLSOFT_COMPILER_IS_DMC)
00190     : private XP 
00191 #else 
00192     : public XP 
00193 #endif 
00194 {
00195 public:
00196     typedef T                       value_type;
00197     typedef XP                      exception_policy_type;
00198     typedef XP                      parent_class_type;
00199     typedef options_verifier<T, XP> class_type;
00200 
00201 public:
00202     options_verifier(T const& value, char const* failureMessage)
00203         : parent_class_type()
00204         , m_value(value)
00205         , m_failureMessage(failureMessage)
00206         , m_bMatched(false)
00207     {}
00208     options_verifier(T const& value, exception_policy_type policy, char const* failureMessage)
00209         : parent_class_type(policy)
00210         , m_value(value)
00211         , m_failureMessage(failureMessage)
00212         , m_bMatched(false)
00213     {}
00214     options_verifier(class_type const& rhs)
00215         : parent_class_type(rhs)
00216         , m_value(rhs.m_value)
00217         , m_failureMessage(rhs.m_failureMessage)
00218         , m_bMatched(rhs.m_bMatched)
00219     {
00220         rhs.m_bMatched = true;
00221     }
00243     ~options_verifier()
00244     {
00245         if( !m_bMatched &&
00246 # if defined(STLSOFT_COMPILER_IS_MWERKS)
00247             1)
00248 # else 
00249             !::std::uncaught_exception())
00250 # endif 
00251         {
00252             exception_policy_type   &policy =   *this;
00253 
00254             policy(m_failureMessage);
00255         }
00256     }
00257 
00258 public:
00259     template <ss_typename_param_k U>
00260     class_type& test(U const& u)
00261     {
00262         if( !m_bMatched &&
00263             m_value == u)
00264         {
00265             m_bMatched = true;
00266         }
00267 
00268         return *this;
00269     }
00270 
00271 private:
00272     T const             &m_value;
00273     char const* const   m_failureMessage;
00274     ss_mutable_k bool   m_bMatched;
00275 
00276 private:
00277     class_type& operator =(class_type const&);
00278 };
00279 
00280 #ifdef STLSOFT_OPTIONS_VERIFIER_REQUIRES_SEPARATE_NS
00281 } 
00282 
00283 using options_verifier_internal_ns::options_verifier;
00284 #endif 
00285 
00286 
00287 template<ss_typename_param_k T>
00288 options_verifier<T> verify_options(T const& value, char const* failureMessage)
00289 {
00290     return options_verifier<T>(value, failureMessage);
00291 }
00292 
00293 template<   ss_typename_param_k T
00294         ,   ss_typename_param_k XP
00295         >
00296 options_verifier<T, XP> verify_options(T const& value, XP const& policy, char const* failureMessage)
00297 {
00298     return options_verifier<T, XP>(value, policy, failureMessage);
00299 }
00300 
00301 #ifdef STLSOFT_OPTIONS_VERIFIER_REQUIRES_SEPARATE_NS
00302 namespace options_verifier_internal_ns
00303 {
00304 #endif 
00305 
00306 template<   ss_typename_param_k T
00307         ,   ss_typename_param_k XP
00308         ,   ss_typename_param_k U
00309         >
00310 inline options_verifier<T, XP>& operator ,(options_verifier<T, XP> &ov, U const& u)
00311 {
00312     return ov.test(u);
00313 }
00314 
00315 #if 1
00316 
00321 template<   ss_typename_param_k T
00322         ,   ss_typename_param_k U
00323         >
00324 class options_verifier_comparison_ref
00325 {
00326 public:
00327     typedef options_verifier<T>                     verifier_type;
00328     typedef options_verifier_comparison_ref<T, U>   class_type;
00329 
00330 public:
00331     options_verifier_comparison_ref(verifier_type *verifier)
00332         : m_verifier(verifier)
00333     {}
00334 
00335     options_verifier_comparison_ref(class_type const& rhs)
00336         : m_verifier(rhs.m_verifier)
00337     {}
00338 
00339 public:
00340     class_type& test(U const& u)
00341     {
00342         m_verifier->test(u);
00343 
00344         return *this;
00345     }
00346 
00347 private:
00348     verifier_type   *m_verifier;
00349 };
00350 
00351 template<   ss_typename_param_k T
00352         ,   ss_typename_param_k U
00353         >
00354 inline options_verifier_comparison_ref<T, U>& operator ==(options_verifier<T> const& ov, U const& u)
00355 {
00356     
00357     
00358     options_verifier_comparison_ref<T, U>   ovcr(const_cast<options_verifier<T>*>(&ov));
00359 
00360     return ovcr.test(u);
00361 }
00362 
00363 template<   ss_typename_param_k T
00364         ,   ss_typename_param_k U1
00365         ,   ss_typename_param_k U2
00366         >
00367 inline options_verifier_comparison_ref<T, U1>& operator ||(options_verifier_comparison_ref<T, U1> &ov, U2 const& u)
00368 {
00369     return ov.test(u);
00370 }
00371 #endif 
00372 
00373 #ifdef STLSOFT_OPTIONS_VERIFIER_REQUIRES_SEPARATE_NS
00374 } 
00375 #endif 
00376 
00378 
00379 
00380 #ifdef STLSOFT_UNITTEST
00381 # include "./unittest/options_verifier_unittest_.h"
00382 #endif 
00383 
00384 
00385 
00386 #ifndef _STLSOFT_NO_NAMESPACE
00387 } 
00388 #endif 
00389 
00390 
00391 
00392 #endif 
00393 
00394