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 
00049 #ifndef COMSTL_INCL_COMSTL_ERROR_HPP_ERRORINFO_DESC
00050 #define COMSTL_INCL_COMSTL_ERROR_HPP_ERRORINFO_DESC
00051 
00052 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00053 # define COMSTL_VER_COMSTL_ERROR_HPP_ERRORINFO_DESC_MAJOR       0
00054 # define COMSTL_VER_COMSTL_ERROR_HPP_ERRORINFO_DESC_MINOR       5
00055 # define COMSTL_VER_COMSTL_ERROR_HPP_ERRORINFO_DESC_REVISION    8
00056 # define COMSTL_VER_COMSTL_ERROR_HPP_ERRORINFO_DESC_EDIT        32
00057 #endif 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 #ifndef COMSTL_INCL_COMSTL_H_COMSTL
00072 # include <comstl/comstl.h>
00073 #endif 
00074 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD
00075 # include <stlsoft/shims/access/string/fwd.h>
00076 #endif 
00077 #ifdef STLSOFT_CF_THROW_BAD_ALLOC
00078 # include <new>
00079 #endif 
00080 
00081 
00082 
00083 
00084 
00085 #ifndef _COMSTL_NO_NAMESPACE
00086 # if defined(_STLSOFT_NO_NAMESPACE) || \
00087      defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00088 
00089 namespace comstl
00090 {
00091 # else
00092 
00093 
00094 namespace stlsoft
00095 {
00096 
00097 namespace comstl_project
00098 {
00099 
00100 # endif 
00101 #endif 
00102 
00103 
00104 
00105 
00106 
00111 class errorinfo_desc
00112 {
00115 public:
00116     typedef errorinfo_desc  class_type;
00118 
00121 public:
00122     errorinfo_desc()
00123         : m_description(NULL)
00124         , m_description_a(NULL)
00125         , m_len(0)
00126     {
00127         IErrorInfo* pei;
00128 
00129         if(S_OK == ::GetErrorInfo(0, &pei))
00130         {
00131             get_description(pei, m_description, m_len);
00132 
00133             pei->Release();
00134         }
00135     }
00136     errorinfo_desc(IErrorInfo* pei)
00137         : m_description(NULL)
00138         , m_description_a(NULL)
00139     {
00140         get_description(pei, m_description, m_len);
00141     }
00142     errorinfo_desc(errorinfo_desc const& rhs)
00143         : m_description(::SysAllocString(rhs.m_description))
00144         , m_description_a(NULL)
00145         , m_len(rhs.m_len)
00146     {}
00147 
00148     ~errorinfo_desc() stlsoft_throw_0()
00149     {
00150         ::SysFreeString(m_description);
00151         ::CoTaskMemFree(m_description_a);
00152     }
00154 
00157 public:
00158     LPCOLESTR c_str_w() const
00159     {
00160         return (NULL == m_description) ? L"" : m_description;
00161     }
00162     char const* c_str_a() const
00163     {
00164         return const_cast<class_type*>(this)->check_description_a_();
00165     }
00166 #ifdef UNICODE
00167     LPCOLESTR c_str() const
00168     {
00169         return c_str_w();
00170     }
00171 #else 
00172     char const* c_str() const
00173     {
00174         return c_str_a();
00175     }
00176 #endif 
00177     cs_size_t length() const
00178     {
00179         return m_len;
00180     }
00182 
00185 private:
00186     char const* check_description_a_()
00187     {
00188         if( NULL == m_description_a &&
00189             NULL != m_description)
00190         {
00191             int cch = ::WideCharToMultiByte(0, 0, m_description, -1, NULL, 0, NULL, NULL);
00192 
00193             m_description_a = static_cast<char*>(::CoTaskMemAlloc((1 + cch) * sizeof(char)));
00194 
00195             if(NULL == m_description_a)
00196             {
00197 #ifdef STLSOFT_CF_THROW_BAD_ALLOC
00198                 STLSOFT_THROW_X(stlsoft_ns_qual_std(bad_alloc)());
00199 #endif 
00200             }
00201             else
00202             {
00203                 ::WideCharToMultiByte(0, 0, m_description, -1, m_description_a, 1 + cch, NULL, NULL);
00204             }
00205         }
00206 
00207         return (NULL == m_description_a) ? "" : m_description_a;
00208     }
00209 
00210     static void get_description(IErrorInfo* pei, BSTR& description, cs_size_t& len)
00211     {
00212         BSTR    bstr;
00213 
00214         if( 0 != pei &&
00215             SUCCEEDED(pei->GetDescription(&bstr)))
00216         {
00217             
00218             
00219             LPOLESTR    begin   =   bstr;
00220             LPOLESTR    end     =   begin + ::SysStringLen(bstr);
00221             LPOLESTR    last    =   end;
00222 
00223             for(; begin != last; --last)
00224             {
00225                 OLECHAR ch = *(last - 1);
00226 
00227                 
00228                 
00229                 if( ch == ' ' ||
00230                     ch == '\t' ||
00231                     ch == '\r' ||
00232                     ch == '\n')
00233                 {
00234                 }
00235                 else
00236                 {
00237                     break;
00238                 }
00239             }
00240 
00241             description = ::SysAllocStringLen(bstr, static_cast<UINT>(last - begin));
00242 
00243             if(NULL == description)
00244             {
00245                 
00246                 description = bstr;
00247             }
00248             else
00249             {
00250                 ::SysFreeString(bstr);
00251             }
00252 
00253             len = static_cast<cs_size_t>(last - begin);
00254         }
00255     }
00257 
00260 private:
00261     BSTR        m_description;
00262     char*       m_description_a;
00263     cs_size_t   m_len;
00265 
00266 
00267 private:
00268     class_type const& operator =(class_type const&);
00269 };
00270 
00271 
00272 
00273 
00274 
00275 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00276 
00277 inline cs_char_a_t const* c_str_data_a(comstl_ns_qual(errorinfo_desc) const& eid)
00278 {
00279     return eid.c_str_a();
00280 }
00281 
00282 inline cs_char_w_t const* c_str_data_w(comstl_ns_qual(errorinfo_desc) const& eid)
00283 {
00284     return eid.c_str_w();
00285 }
00286 
00287 inline cs_char_o_t const* c_str_data_o(comstl_ns_qual(errorinfo_desc) const& eid)
00288 {
00289     return eid.c_str_w();
00290 }
00291 
00292 #endif 
00293 
00298 inline LPCTSTR c_str_data(comstl_ns_qual(errorinfo_desc) const& eid)
00299 {
00300     return eid.c_str();
00301 }
00302 
00303 
00304 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00305 
00306 inline cs_size_t c_str_len_a(comstl_ns_qual(errorinfo_desc) const& eid)
00307 {
00308     return eid.length();
00309 }
00310 
00311 inline cs_size_t c_str_len_w(comstl_ns_qual(errorinfo_desc) const& eid)
00312 {
00313     return eid.length();
00314 }
00315 
00316 inline cs_size_t c_str_len_o(comstl_ns_qual(errorinfo_desc) const& eid)
00317 {
00318     return eid.length();
00319 }
00320 
00321 #endif 
00322 
00327 inline cs_size_t c_str_len(comstl_ns_qual(errorinfo_desc) const& eid)
00328 {
00329     return eid.length();
00330 }
00331 
00332 
00333 
00334 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00335 
00336 inline cs_char_a_t const* c_str_ptr_a(comstl_ns_qual(errorinfo_desc) const& eid)
00337 {
00338     return eid.c_str_a();
00339 }
00340 
00341 inline cs_char_w_t const* c_str_ptr_w(comstl_ns_qual(errorinfo_desc) const& eid)
00342 {
00343     return eid.c_str_w();
00344 }
00345 
00346 inline cs_char_o_t const* c_str_ptr_o(comstl_ns_qual(errorinfo_desc) const& eid)
00347 {
00348     return eid.c_str_w();
00349 }
00350 
00351 #endif 
00352 
00357 inline LPCTSTR c_str_ptr(comstl_ns_qual(errorinfo_desc) const& eid)
00358 {
00359     return eid.c_str();
00360 }
00361 
00362 
00363 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00364 
00365 inline cs_char_a_t const* c_str_ptr_null_a(comstl_ns_qual(errorinfo_desc) const& eid)
00366 {
00367     return (0 != eid.length()) ? eid.c_str_a() : NULL;
00368 }
00369 
00370 inline cs_char_w_t const* c_str_ptr_null_w(comstl_ns_qual(errorinfo_desc) const& eid)
00371 {
00372     return (0 != eid.length()) ? eid.c_str_w() : NULL;
00373 }
00374 
00375 inline cs_char_o_t const* c_str_ptr_null_o(comstl_ns_qual(errorinfo_desc) const& eid)
00376 {
00377     return (0 != eid.length()) ? eid.c_str_w() : NULL;
00378 }
00379 
00380 #endif 
00381 
00386 inline LPCTSTR c_str_ptr_null(comstl_ns_qual(errorinfo_desc) const& eid)
00387 {
00388     return (0 != eid.length()) ? eid.c_str() : NULL;
00389 }
00390 
00391 
00396 template<   ss_typename_param_k S
00397         >
00398 inline S& operator <<(S& s, comstl_ns_qual(errorinfo_desc) const& eid)
00399 {
00400     s << eid.c_str();
00401 
00402     return s;
00403 }
00404 
00405 
00406 
00407 #ifndef _COMSTL_NO_NAMESPACE
00408 # if defined(_STLSOFT_NO_NAMESPACE) || \
00409      defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00410 } 
00411 # else
00412 } 
00413 } 
00414 # endif 
00415 #endif 
00416 
00417 
00418 
00419 
00420 
00421 
00422 
00423 
00424 
00425 #ifndef _COMSTL_NO_NAMESPACE
00426 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00427      !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00428 namespace stlsoft
00429 {
00430 # else 
00431 
00432 # endif 
00433 
00434 using ::comstl::c_str_data;
00435 using ::comstl::c_str_data_a;
00436 using ::comstl::c_str_data_w;
00437 using ::comstl::c_str_data_o;
00438 
00439 using ::comstl::c_str_len;
00440 using ::comstl::c_str_len_a;
00441 using ::comstl::c_str_len_w;
00442 using ::comstl::c_str_len_o;
00443 
00444 using ::comstl::c_str_ptr;
00445 using ::comstl::c_str_ptr_a;
00446 using ::comstl::c_str_ptr_w;
00447 using ::comstl::c_str_ptr_o;
00448 
00449 using ::comstl::c_str_ptr_null;
00450 using ::comstl::c_str_ptr_null_a;
00451 using ::comstl::c_str_ptr_null_w;
00452 using ::comstl::c_str_ptr_null_o;
00453 
00454 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00455      !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00456 } 
00457 # else 
00458 
00459 # endif 
00460 #endif 
00461 
00462 
00463 
00464 #endif 
00465 
00466