Skip to content

Commit

Permalink
Added boost::property_tree
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalev Lember committed Dec 2, 2010
1 parent 24d149a commit 055d2f5
Show file tree
Hide file tree
Showing 31 changed files with 7,730 additions and 0 deletions.
84 changes: 84 additions & 0 deletions boost/optional/optional_io.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (C) 2005, Fernando Luis Cacciola Carballal.
//
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/optional for documentation.
//
// You are welcome to contact the author at:
// [email protected]
//
#ifndef BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP
#define BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP

#if defined __GNUC__
# if (__GNUC__ == 2 && __GNUC_MINOR__ <= 97)
# define BOOST_OPTIONAL_NO_TEMPLATED_STREAMS
# endif
#endif // __GNUC__

#if defined BOOST_OPTIONAL_NO_TEMPLATED_STREAMS
# include <iostream>
#else
# include <istream>
# include <ostream>
#endif


#include "boost/optional/optional.hpp"
#include "boost/utility/value_init.hpp"

namespace boost
{

#if defined (BOOST_NO_TEMPLATED_STREAMS)
template<class T>
inline std::ostream& operator<<(std::ostream& out, optional<T> const& v)
#else
template<class CharType, class CharTrait, class T>
inline
std::basic_ostream<CharType, CharTrait>&
operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T> const& v)
#endif
{
if ( out.good() )
{
if ( !v )
out << "--" ;
else out << ' ' << *v ;
}

return out;
}

#if defined (BOOST_NO_TEMPLATED_STREAMS)
template<class T>
inline std::istream& operator>>(std::istream& in, optional<T>& v)
#else
template<class CharType, class CharTrait, class T>
inline
std::basic_istream<CharType, CharTrait>&
operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v)
#endif
{
if ( in.good() )
{
int d = in.get();
if ( d == ' ' )
{
T x ;
in >> x;
v = x ;
}
else
v = optional<T>() ;
}

return in;
}

} // namespace boost

#endif

83 changes: 83 additions & 0 deletions boost/property_tree/detail/exception_implementation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// ----------------------------------------------------------------------------
// Copyright (C) 2002-2006 Marcin Kalicinski
// Copyright (C) 2009 Sebastian Redl
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// ----------------------------------------------------------------------------
#ifndef BOOST_PROPERTY_TREE_DETAIL_EXCEPTIONS_IMPLEMENTATION_HPP_INCLUDED
#define BOOST_PROPERTY_TREE_DETAIL_EXCEPTIONS_IMPLEMENTATION_HPP_INCLUDED

namespace boost { namespace property_tree
{

namespace detail
{

// Helper for preparing what string in ptree_bad_path exception
template<class P> inline
std::string prepare_bad_path_what(const std::string &what,
const P &path)
{
return what + " (" + path.dump() + ")";
}

}

///////////////////////////////////////////////////////////////////////////
// ptree_error

inline ptree_error::ptree_error(const std::string &what):
std::runtime_error(what)
{
}

inline ptree_error::~ptree_error() throw()
{
}

///////////////////////////////////////////////////////////////////////////
// ptree_bad_data

template<class D> inline
ptree_bad_data::ptree_bad_data(const std::string &what, const D &data):
ptree_error(what), m_data(data)
{
}

inline ptree_bad_data::~ptree_bad_data() throw()
{
}

template<class D> inline
D ptree_bad_data::data()
{
return boost::any_cast<D>(m_data);
}

///////////////////////////////////////////////////////////////////////////
// ptree_bad_path

template<class P> inline
ptree_bad_path::ptree_bad_path(const std::string &what, const P &path):
ptree_error(detail::prepare_bad_path_what(what, path)), m_path(path)
{

}

inline ptree_bad_path::~ptree_bad_path() throw()
{
}

template<class P> inline
P ptree_bad_path::path()
{
return boost::any_cast<P>(m_path);
}

}}

#endif
93 changes: 93 additions & 0 deletions boost/property_tree/detail/file_parser_error.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// ----------------------------------------------------------------------------
// Copyright (C) 2002-2006 Marcin Kalicinski
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// ----------------------------------------------------------------------------
#ifndef BOOST_PROPERTY_TREE_DETAIL_FILE_PARSER_ERROR_HPP_INCLUDED
#define BOOST_PROPERTY_TREE_DETAIL_FILE_PARSER_ERROR_HPP_INCLUDED

#include <boost/property_tree/ptree.hpp>
#include <string>

namespace boost { namespace property_tree
{

//! File parse error
class file_parser_error: public ptree_error
{

public:

///////////////////////////////////////////////////////////////////////
// Construction & destruction

// Construct error
file_parser_error(const std::string &message,
const std::string &filename,
unsigned long line) :
ptree_error(format_what(message, filename, line)),
m_message(message), m_filename(filename), m_line(line)
{
}

~file_parser_error() throw()
// gcc 3.4.2 complains about lack of throw specifier on compiler
// generated dtor
{
}

///////////////////////////////////////////////////////////////////////
// Data access

// Get error message (without line and file - use what() to get
// full message)
std::string message()
{
return m_message;
}

// Get error filename
std::string filename()
{
return m_filename;
}

// Get error line number
unsigned long line()
{
return m_line;
}

private:

std::string m_message;
std::string m_filename;
unsigned long m_line;

// Format error message to be returned by std::runtime_error::what()
std::string format_what(const std::string &message,
const std::string &filename,
unsigned long line)
{
std::stringstream stream;
if (line > 0)
stream << (filename.empty() ? "<unspecified file>"
: filename.c_str())
<< '(' << line << "): "
<< message;
else
stream << (filename.empty() ? "<unspecified file>"
: filename.c_str())
<< ": " << message;
return stream.str();
}

};

} }

#endif
32 changes: 32 additions & 0 deletions boost/property_tree/detail/info_parser_error.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ----------------------------------------------------------------------------
// Copyright (C) 2002-2006 Marcin Kalicinski
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// ----------------------------------------------------------------------------
#ifndef BOOST_PROPERTY_TREE_DETAIL_INFO_PARSER_ERROR_HPP_INCLUDED
#define BOOST_PROPERTY_TREE_DETAIL_INFO_PARSER_ERROR_HPP_INCLUDED

#include <boost/property_tree/detail/file_parser_error.hpp>
#include <string>

namespace boost { namespace property_tree { namespace info_parser
{

class info_parser_error: public file_parser_error
{
public:
info_parser_error(const std::string &message,
const std::string &filename,
unsigned long line) :
file_parser_error(message, filename, line)
{
}
};

} } }

#endif
Loading

0 comments on commit 055d2f5

Please sign in to comment.