GraphLab: Distributed Graph-Parallel API
2.1
|
#include <graphlab/util/generics/any.hpp>
Classes | |
class | holder |
Public Types | |
typedef iholder *(* | deserialize_function_type )(iarchive_soft_fail &arc) |
typedef std::map< uint64_t, deserialize_function_type > | registry_map_type |
Public Member Functions | |
any () | |
default constructor. Creates an empty any | |
template<typename ValueType > | |
any (const ValueType &value) | |
Creates an any which stores the value. | |
any (const any &other) | |
Construct an any from another any. | |
~any () | |
Destroy the contentss of this any. | |
bool | empty () const |
Returns true if the object does not contain any stored data. | |
template<typename ValueType > | |
ValueType & | as () |
template<typename ValueType > | |
const ValueType & | as () const |
any & | swap (any &rhs) |
Exchanges the contents of two any's. | |
template<typename ValueType > | |
any & | operator= (const ValueType &rhs) |
any & | operator= (const any &rhs) |
std::ostream & | print (std::ostream &out) const |
const std::type_info & | type () const |
Returns the type information of the stored data. | |
const std::string | type_name () const |
Return the name of the internal type as a string. | |
void | load (iarchive &arc) |
loads the any from a file. | |
void | save (oarchive &arc) const |
Saves the any to a file. Caveats apply. See the main any docs. |
Static Public Member Functions | |
static registry_map_type & | get_global_registry () |
template<typename ValueType > | |
static boost::disable_if_c < boost::is_output_streamable < ValueType >::value, void > ::type | print_type_or_contents (std::ostream &out, const ValueType &h) |
template<typename ValueType > | |
static boost::enable_if_c < boost::is_output_streamable < ValueType >::value, void > ::type | print_type_or_contents (std::ostream &out, const ValueType &h) |
A generic "variant" object obtained from Boost::Any and modified to be serializable. A variable of type "any" can store any datatype (even dynamically changeable at runtime), but the caveat is that you must know the exact stored type to be able to extract the data safely.
To serialize/deserialize the any, regular serialization procedures apply. However, since a statically initialized type registration system is used to identify the type of the deserialized object, so the user must pay attention to a couple of minor issues.
On serialization:
On deserialization:
Condition d) is particular unusual so I will illustrate with an example.
Given a simple user struct:
If an any object contains the struct, it will be serializable.
To deserialize, I will open an input archive and stream into an any.
Now, unusually, the above code will fail, while the following code will succeed
The a.as<UserStruct>()
forces the instantiation of static functions which allow the any deserialization to identify the UserStruct type.
typedef iholder*(* graphlab::any::deserialize_function_type)(iarchive_soft_fail &arc) |
|
inline |
|
inline |
|
static |
The get registry routine is a static method that gets a reference to the global registry. It is very important that this be a static method and not a static member to ensure that the global registry is defined before each holders try to register. This is accomplished by having get_registry statically declare the global registry
Define the static registry for any
|
inline |