Changeset 34254

Show
Ignore:
Timestamp:
07/03/09 09:32:10 (4 years ago)
Author:
kazuho
Message:

operator <<>>, example

Location:
lang/cplusplus/picojson/trunk
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • lang/cplusplus/picojson/trunk/picojson.h

    r34241 r34254  
    588588  } 
    589589   
     590  template <bool FALSE> struct last_error_t { 
     591    static std::string s; 
     592  }; 
     593  template <bool FALSE> std::string last_error_t<FALSE>::s; 
     594   
     595  inline void set_last_error(const std::string& s) { 
     596    last_error_t<false>::s = s; 
     597  } 
     598   
     599  inline const std::string& get_last_error() { 
     600    return last_error_t<false>::s; 
     601  } 
     602} 
     603 
     604inline std::istream& operator>>(std::istream& is, picojson::value& x) 
     605{ 
     606  picojson::set_last_error(std::string()); 
     607  std::string err = picojson::parse(x, is); 
     608  if (! err.empty()) { 
     609    picojson::set_last_error(err); 
     610    is.setstate(std::ios::failbit); 
     611  } 
     612  return is; 
     613} 
     614 
     615inline std::ostream& operator<<(std::ostream& os, const picojson::value& x) 
     616{ 
     617  x.serialize(std::ostream_iterator<char>(os)); 
     618  return os; 
    590619} 
    591620