Ticket #8631: property_pree_locale.patch

File property_pree_locale.patch, 9.9 KB (added by shirshov evgeny <381677383@…>, 9 years ago)
  • detail/ptree_implementation.hpp

     
    655655
    656656    template<class K, class D, class C>
    657657    template<class Type> inline
    658     Type basic_ptree<K, D, C>::get_value() const
     658    Type basic_ptree<K, D, C>::get_value(const std::locale & loc) const
    659659    {
    660660        return get_value<Type>(
    661             typename translator_between<data_type, Type>::type());
     661            typename translator_between<data_type, Type>::type(loc));
    662662    }
    663663
    664664    template<class K, class D, class C>
     
    683683    template<class K, class D, class C>
    684684    template<class Type> inline
    685685    typename boost::disable_if<detail::is_translator<Type>, Type>::type
    686     basic_ptree<K, D, C>::get_value(const Type &default_value) const
     686    basic_ptree<K, D, C>::get_value(const Type &default_value, const std::locale & loc) const
    687687    {
    688688        return get_value(default_value,
    689                          typename translator_between<data_type, Type>::type());
     689                         typename translator_between<data_type, Type>::type(loc));
    690690    }
    691691
    692692    template<class K, class D, class C>
     
    710710
    711711    template<class K, class D, class C>
    712712    template<class Type> inline
    713     optional<Type> basic_ptree<K, D, C>::get_value_optional() const
     713    optional<Type> basic_ptree<K, D, C>::get_value_optional(const std::locale & loc) const
    714714    {
    715715        return get_value_optional<Type>(
    716             typename translator_between<data_type, Type>::type());
     716            typename translator_between<data_type, Type>::type(loc));
    717717    }
    718718
    719719    template<class K, class D, class C>
     
    727727
    728728    template<class K, class D, class C>
    729729    template<class Type> inline
    730     Type basic_ptree<K, D, C>::get(const path_type &path) const
     730    Type basic_ptree<K, D, C>::get(const path_type &path, const std::locale & loc) const
    731731    {
    732         return get_child(path).BOOST_NESTED_TEMPLATE get_value<Type>();
     732        return get_child(path).BOOST_NESTED_TEMPLATE get_value<Type>(loc);
    733733    }
    734734
    735735    template<class K, class D, class C>
     
    757757    template<class Type> inline
    758758    typename boost::disable_if<detail::is_translator<Type>, Type>::type
    759759    basic_ptree<K, D, C>::get(const path_type &path,
    760                               const Type &default_value) const
     760                              const Type &default_value, const std::locale & loc) const
    761761    {
    762         return get_optional<Type>(path).get_value_or(default_value);
     762        return get_optional<Type>(path, loc).get_value_or(default_value);
    763763    }
    764764
    765765    template<class K, class D, class C>
     
    789789    template<class K, class D, class C>
    790790    template<class Type>
    791791    optional<Type> basic_ptree<K, D, C>::get_optional(
    792                                                 const path_type &path) const
     792                                                const path_type &path, const std::locale & loc) const
    793793    {
    794794        if (optional<const self_type&> child = get_child_optional(path))
    795             return child.get().BOOST_NESTED_TEMPLATE get_value_optional<Type>();
     795            return child.get().BOOST_NESTED_TEMPLATE get_value_optional<Type>(loc);
    796796        else
    797797            return optional<Type>();
    798798    }
     
    812812
    813813    template<class K, class D, class C>
    814814    template<class Type> inline
    815     void basic_ptree<K, D, C>::put_value(const Type &value)
     815    void basic_ptree<K, D, C>::put_value(const Type &value, const std::locale & loc)
    816816    {
    817         put_value(value, typename translator_between<data_type, Type>::type());
     817        put_value(value, typename translator_between<data_type, Type>::type(loc));
    818818    }
    819819
    820820    template<class K, class D, class C>
     
    835835    template<class K, class D, class C>
    836836    template<class Type> inline
    837837    basic_ptree<K, D, C> & basic_ptree<K, D, C>::put(
    838         const path_type &path, const Type &value)
     838        const path_type &path, const Type &value, const std::locale & loc)
    839839    {
    840840        return put(path, value,
    841                    typename translator_between<data_type, Type>::type());
     841                   typename translator_between<data_type, Type>::type(loc));
    842842    }
    843843
    844844    template<class K, class D, class C>
     
    854854    template<class K, class D, class C>
    855855    template<class Type> inline
    856856    basic_ptree<K, D, C> & basic_ptree<K, D, C>::add(
    857         const path_type &path, const Type &value)
     857        const path_type &path, const Type &value, const std::locale & loc)
    858858    {
    859859        return add(path, value,
    860                    typename translator_between<data_type, Type>::type());
     860                   typename translator_between<data_type, Type>::type(loc));
    861861    }
    862862
    863863
  • id_translator.hpp

     
    2828
    2929        boost::optional<T> get_value(const T &v) { return v; }
    3030        boost::optional<T> put_value(const T &v) { return v; }
     31
     32        explicit id_translator()
     33        {
     34        }
     35        explicit id_translator(const std::locale &)
     36        {
     37        }
    3138    };
    3239
    3340    // This is the default translator whenever you get two equal types.
  • ptree.hpp

     
    310310         * @throw ptree_bad_data if the conversion fails.
    311311         */
    312312        template<class Type>
    313         Type get_value() const;
     313        Type get_value(const std::locale & loc = std::locale()) const;
    314314
    315315        /** Take the value of this node and attempt to translate it to a
    316316         * @c Type object using the supplied translator. Return @p default_value
     
    333333         */
    334334        template<class Type>
    335335        typename boost::disable_if<detail::is_translator<Type>, Type>::type
    336         get_value(const Type &default_value) const;
     336        get_value(const Type &default_value, const std::locale & loc = std::locale()) const;
    337337
    338338        /** Make get_value do the right thing for string literals. */
    339339        template <class Ch>
     
    355355         * this fails.
    356356         */
    357357        template<class Type>
    358         optional<Type> get_value_optional() const;
     358        optional<Type> get_value_optional(const std::locale & loc = std::locale()) const;
    359359
    360360        /** Replace the value at this node with the given value, translated
    361361         * to the tree's data type using the supplied translator.
     
    369369         * @throw ptree_bad_data if the conversion fails.
    370370        */
    371371        template<class Type>
    372         void put_value(const Type &value);
     372        void put_value(const Type &value, const std::locale & loc = std::locale());
    373373
    374374        /** Shorthand for get_child(path).get_value(tr). */
    375375        template<class Type, class Translator>
     
    378378
    379379        /** Shorthand for get_child(path).get_value\<Type\>(). */
    380380        template<class Type>
    381         Type get(const path_type &path) const;
     381        Type get(const path_type &path, const std::locale & loc = std::locale()) const;
    382382
    383383        /** Shorthand for get_child(path, empty_ptree())
    384384         *                    .get_value(default_value, tr).
     
    405405         */
    406406        template<class Type>
    407407        typename boost::disable_if<detail::is_translator<Type>, Type>::type
    408         get(const path_type &path, const Type &default_value) const;
     408        get(const path_type &path, const Type &default_value, const std::locale & loc = std::locale()) const;
    409409
    410410        /** Make get do the right thing for string literals. */
    411411        template <class Ch>
     
    435435         * That is, return the value if it exists and can be converted, or nil.
    436436        */
    437437        template<class Type>
    438         optional<Type> get_optional(const path_type &path) const;
     438        optional<Type> get_optional(const path_type &path, const std::locale & loc = std::locale()) const;
    439439
    440440        /** Set the value of the node at the given path to the supplied value,
    441441         * translated to the tree's data type. If the node doesn't exist, it is
     
    453453         * @throw ptree_bad_data if the conversion fails.
    454454        */
    455455        template<class Type>
    456         self_type &put(const path_type &path, const Type &value);
     456        self_type &put(const path_type &path, const Type &value, const std::locale & loc = std::locale());
    457457
    458458        /** If the node identified by the path does not exist, create it,
    459459         * including all its missing parents.
     
    484484         * @throw ptree_bad_data if the conversion fails.
    485485        */
    486486        template<class Type>
    487         self_type &add(const path_type &path, const Type &value);
     487        self_type &add(const path_type &path, const Type &value, const std::locale & loc = std::locale());
    488488
    489489    private:
    490490        // Hold the data of this node
  • stream_translator.hpp

     
    140140                i < (std::numeric_limits<signed char>::min)())
    141141            {
    142142                s.clear(); // guarantees eof to be unset
     143                s.setstate(std::ios_base::badbit);
    143144                return;
    144145            }
    145146            e = (signed char)i;
     
    161162            // out of range?
    162163            if(i > (std::numeric_limits<unsigned char>::max)()) {
    163164                s.clear(); // guarantees eof to be unset
     165                s.setstate(std::ios_base::badbit);
    164166                return;
    165167            }
    166168            e = (unsigned char)i;
     
    179181        typedef std::basic_string<Ch, Traits, Alloc> internal_type;
    180182        typedef E external_type;
    181183
    182         explicit stream_translator(std::locale loc = std::locale())
     184        explicit stream_translator(std::locale loc)
    183185            : m_loc(loc)
    184186        {}
    185187