id_translator.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // ----------------------------------------------------------------------------
  2. // Copyright (C) 2009 Sebastian Redl
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see www.boost.org
  9. // ----------------------------------------------------------------------------
  10. #ifndef BOOST_PROPERTY_TREE_ID_TRANSLATOR_HPP_INCLUDED
  11. #define BOOST_PROPERTY_TREE_ID_TRANSLATOR_HPP_INCLUDED
  12. #include <boost/property_tree/ptree_fwd.hpp>
  13. #include <boost/optional.hpp>
  14. #include <string>
  15. namespace boost { namespace property_tree
  16. {
  17. /// Simple implementation of the Translator concept. It does no translation.
  18. template <typename T>
  19. struct id_translator
  20. {
  21. typedef T internal_type;
  22. typedef T external_type;
  23. boost::optional<T> get_value(const T &v) { return v; }
  24. boost::optional<T> put_value(const T &v) { return v; }
  25. };
  26. // This is the default translator whenever you get two equal types.
  27. template <typename T>
  28. struct translator_between<T, T>
  29. {
  30. typedef id_translator<T> type;
  31. };
  32. // A more specific specialization for std::basic_string. Otherwise,
  33. // stream_translator's specialization wins.
  34. template <typename Ch, typename Traits, typename Alloc>
  35. struct translator_between< std::basic_string<Ch, Traits, Alloc>,
  36. std::basic_string<Ch, Traits, Alloc> >
  37. {
  38. typedef id_translator< std::basic_string<Ch, Traits, Alloc> > type;
  39. };
  40. }}
  41. #endif