2019-09-04 00:56:52 -04:00
|
|
|
[/
|
|
|
|
|
Copyright 2019 Glen Joseph Fernandes
|
|
|
|
|
(glenjofe@gmail.com)
|
|
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0.
|
|
|
|
|
(http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
[section:nvp nvp]
|
|
|
|
|
|
|
|
|
|
[section Overview]
|
|
|
|
|
|
|
|
|
|
The header <boost/core/nvp.hpp> provides the class template `boost::nvp` that
|
|
|
|
|
pairs a name (`const char*`) with the address of a value (`T*`). It is the new
|
|
|
|
|
implementation of the NVP type previously provided by the Boost Serialization
|
|
|
|
|
library. This type now lives in the Core library so that other Boost libraries
|
|
|
|
|
can support named value serialization without taking a dependency on the
|
|
|
|
|
Serialization library.
|
|
|
|
|
|
|
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[section Examples]
|
|
|
|
|
|
|
|
|
|
The following snippet shows use in a member serialize function:
|
|
|
|
|
|
|
|
|
|
```
|
2019-09-04 12:28:00 -04:00
|
|
|
template<class A>
|
|
|
|
|
void serialize(A& archive, unsigned)
|
2019-09-04 00:56:52 -04:00
|
|
|
{
|
|
|
|
|
archive & boost::make_nvp("x", x_) & boost::make_nvp("y", y_);
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[section Reference]
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
namespace boost {
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
class nvp {
|
2019-09-04 20:04:27 -04:00
|
|
|
public:
|
2019-09-04 00:56:52 -04:00
|
|
|
nvp(const char* name, T& value) noexcept;
|
|
|
|
|
|
|
|
|
|
const char* name() const noexcept;
|
|
|
|
|
|
|
|
|
|
T& value() const noexcept;
|
|
|
|
|
|
|
|
|
|
const T& const_value() const noexcept;
|
|
|
|
|
|
2019-09-04 12:28:00 -04:00
|
|
|
template<class A>
|
2019-09-10 08:04:40 -04:00
|
|
|
void serialize(A& archive, unsigned);
|
2019-09-04 00:56:52 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
struct is_nvp;
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
const nvp<T> make_nvp(const char* name, T& value) noexcept;
|
|
|
|
|
|
|
|
|
|
} /* boost */
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
[section Constructors]
|
|
|
|
|
|
|
|
|
|
[variablelist
|
|
|
|
|
[[`nvp(const char* name, T& value) noexcept;`]
|
|
|
|
|
[Initializes the stored name pointer with `name` and the value pointer with
|
|
|
|
|
`addressof(value)`.]]]
|
|
|
|
|
|
|
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[section Members]
|
|
|
|
|
|
|
|
|
|
[variablelist
|
|
|
|
|
[[`const char* name() const noexcept;`]
|
2019-09-04 20:04:27 -04:00
|
|
|
[Returns a pointer to the name.]]
|
2019-09-04 00:56:52 -04:00
|
|
|
[[`T& value() const noexcept;`]
|
2019-09-04 20:04:27 -04:00
|
|
|
[Returns a reference to the value.]]
|
2019-09-04 00:56:52 -04:00
|
|
|
[[`const T& const_value() const noexcept;`]
|
2019-09-04 20:04:27 -04:00
|
|
|
[Returns a reference to the value.]]
|
2019-09-10 08:04:40 -04:00
|
|
|
[[`template<class A> void serialize(A& archive, unsigned);`]
|
2019-09-04 20:04:27 -04:00
|
|
|
[Calls `archive.operator<<(const_value())` if `A::is_saving` is a true type,
|
|
|
|
|
otherwise `archive.operator>>(value())`.]]]
|
2019-09-04 00:56:52 -04:00
|
|
|
|
|
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[section Traits]
|
|
|
|
|
|
|
|
|
|
[variablelist
|
2019-09-04 20:04:27 -04:00
|
|
|
[[`template<class T> struct is_nvp;`]
|
2019-09-04 00:56:52 -04:00
|
|
|
[Provides static constant `value` equal to true if `T` is an NVP type,
|
|
|
|
|
otherwise false.]]]
|
|
|
|
|
|
|
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[section Functions]
|
|
|
|
|
|
|
|
|
|
[variablelist
|
|
|
|
|
[[`template<class T> const nvp<T> make_nvp(const char* name, T& value)
|
|
|
|
|
noexcept;`]
|
|
|
|
|
[Returns `nvp<T>(name, value)`.]]]
|
|
|
|
|
|
|
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[section Acknowledgments]
|
|
|
|
|
|
2019-09-04 20:04:27 -04:00
|
|
|
Robert Ramey originally implemented NVP in the Serialization library. Glen
|
2019-09-04 00:56:52 -04:00
|
|
|
Fernandes implemented this new (but compatible) version in the Core library.
|
|
|
|
|
|
|
|
|
|
[endsect]
|
|
|
|
|
|
|
|
|
|
[endsect]
|