BVB Source Codes

mars Show info.hpp Source code

Return Download mars: download info.hpp Source code - Download mars Source code - Type:.hpp
  1. //Copyright (c) 2006-2010 Emil Dotchevski and Reverge Studios, Inc.
  2.  
  3. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5.  
  6. #ifndef UUID_8D22C4CA9CC811DCAA9133D256D89593
  7. #define UUID_8D22C4CA9CC811DCAA9133D256D89593
  8. #if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  9. #pragma GCC system_header
  10. #endif
  11. #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  12. #pragma warning(push,1)
  13. #endif
  14.  
  15. #include <boost/exception/exception.hpp>
  16. #include <boost/exception/to_string_stub.hpp>
  17. #include <boost/exception/detail/error_info_impl.hpp>
  18. #include <boost/shared_ptr.hpp>
  19. #include <boost/config.hpp>
  20. #include <map>
  21.  
  22. namespace mars_boost {} namespace boost = mars_boost; namespace
  23. mars_boost
  24.     {
  25.     template <class Tag,class T>
  26.     inline
  27.     std::string
  28.     error_info_name( error_info<Tag,T> const & x )
  29.         {
  30.         return tag_type_name<Tag>();
  31.         }
  32.  
  33.     template <class Tag,class T>
  34.     inline
  35.     std::string
  36.     to_string( error_info<Tag,T> const & x )
  37.         {
  38.         return '[' + error_info_name(x) + "] = " + to_string_stub(x.value()) + '\n';
  39.         }
  40.  
  41.     template <class Tag,class T>
  42.     inline
  43.     error_info<Tag,T>::
  44.     error_info( value_type const & value ):
  45.         value_(value)
  46.         {
  47.         }
  48.  
  49.     template <class Tag,class T>
  50.     inline
  51.     error_info<Tag,T>::
  52.     ~error_info() throw()
  53.         {
  54.         }
  55.  
  56.     template <class Tag,class T>
  57.     inline
  58.     std::string
  59.     error_info<Tag,T>::
  60.     name_value_string() const
  61.         {
  62.         return to_string_stub(*this);
  63.         }
  64.  
  65.     namespace
  66.     exception_detail
  67.         {
  68.         class
  69.         error_info_container_impl:
  70.             public error_info_container
  71.             {
  72.             public:
  73.  
  74.             error_info_container_impl():
  75.                 count_(0)
  76.                 {
  77.                 }
  78.  
  79.             ~error_info_container_impl() throw()
  80.                 {
  81.                 }
  82.  
  83.             void
  84.             set( shared_ptr<error_info_base> const & x, type_info_ const & typeid_ )
  85.                 {
  86.                 BOOST_ASSERT(x);
  87.                 info_[typeid_] = x;
  88.                 diagnostic_info_str_.clear();
  89.                 }
  90.  
  91.             shared_ptr<error_info_base>
  92.             get( type_info_ const & ti ) const
  93.                 {
  94.                 error_info_map::const_iterator i=info_.find(ti);
  95.                 if( info_.end()!=i )
  96.                     {
  97.                     shared_ptr<error_info_base> const & p = i->second;
  98. #ifndef BOOST_NO_RTTI
  99.                     BOOST_ASSERT( *BOOST_EXCEPTION_DYNAMIC_TYPEID(*p).type_==*ti.type_ );
  100. #endif
  101.                     return p;
  102.                     }
  103.                 return shared_ptr<error_info_base>();
  104.                 }
  105.  
  106.             char const *
  107.             diagnostic_information( char const * header ) const
  108.                 {
  109.                 if( header )
  110.                     {
  111.                     std::ostringstream tmp;
  112.                     tmp << header;
  113.                     for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )
  114.                         {
  115.                         error_info_base const & x = *i->second;
  116.                         tmp << x.name_value_string();
  117.                         }
  118.                     tmp.str().swap(diagnostic_info_str_);
  119.                     }
  120.                 return diagnostic_info_str_.c_str();
  121.                 }
  122.  
  123.             private:
  124.  
  125.             friend class mars_boost::exception;
  126.  
  127.             typedef std::map< type_info_, shared_ptr<error_info_base> > error_info_map;
  128.             error_info_map info_;
  129.             mutable std::string diagnostic_info_str_;
  130.             mutable int count_;
  131.  
  132.             error_info_container_impl( error_info_container_impl const & );
  133.             error_info_container_impl & operator=( error_info_container const & );
  134.  
  135.             void
  136.             add_ref() const
  137.                 {
  138.                 ++count_;
  139.                 }
  140.  
  141.             bool
  142.             release() const
  143.                 {
  144.                 if( --count_ )
  145.                     return false;
  146.                 else
  147.                     {
  148.                     delete this;
  149.                     return true;
  150.                     }
  151.                 }
  152.  
  153.             refcount_ptr<error_info_container>
  154.             clone() const
  155.                 {
  156.                 refcount_ptr<error_info_container> p;
  157.                 error_info_container_impl * c=new error_info_container_impl;
  158.                 p.adopt(c);
  159.                 c->info_ = info_;
  160.                 return p;
  161.                 }
  162.             };
  163.  
  164.         template <class E,class Tag,class T>
  165.         inline
  166.         E const &
  167.         set_info( E const & x, error_info<Tag,T> const & v )
  168.             {
  169.             typedef error_info<Tag,T> error_info_tag_t;
  170.             shared_ptr<error_info_tag_t> p( new error_info_tag_t(v) );
  171.             exception_detail::error_info_container * c=x.data_.get();
  172.             if( !c )
  173.                 x.data_.adopt(c=new exception_detail::error_info_container_impl);
  174.             c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t));
  175.             return x;
  176.             }
  177.  
  178.         template <class T>
  179.         struct
  180.         derives_boost_exception
  181.             {
  182.             enum e { value = (sizeof(dispatch_boost_exception((T*)0))==sizeof(large_size)) };
  183.             };
  184.         }
  185.  
  186.     template <class E,class Tag,class T>
  187.     inline
  188.     typename enable_if<exception_detail::derives_boost_exception<E>,E const &>::type
  189.     operator<<( E const & x, error_info<Tag,T> const & v )
  190.         {
  191.         return exception_detail::set_info(x,v);
  192.         }
  193.     }
  194.  
  195. #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  196. #pragma warning(pop)
  197. #endif
  198. #endif
  199.  
downloadinfo.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top