Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

serializers.hpp File Reference

#include <s11n.net/s11n/classload.hpp>
#include <s11n.net/s11n/io/data_node_io.hpp>
#include <s11n.net/s11n/s11n_config.hpp>

Go to the source code of this file.

Namespaces

namespace  s11n
namespace  s11n::io

Defines

#define s11n_SERIALIZERS_HPP_INCLUDED   1

Functions

template<typename NodeT, typename ListT>
void serializer_list (ListT &target, bool onlyShortNames=true)
 Intended mainly as a convenience for client applications, serializer_list() populates the target list with the names of registered Serializers.
template<typename SerializerT>
void register_serializer (const std::string &classname, const std::string &alias)
 Registers a Serializer type with the s11n::io layer.
template<typename NodeT>
s11n::io::data_node_serializer<
NodeT > * 
create_serializer (const std::string &classname)
 Returns a new instance of the given serializer class, or 0 if one could not be loaded.


Define Documentation

#define s11n_SERIALIZERS_HPP_INCLUDED   1
 

Definition at line 2 of file serializers.hpp.


Function Documentation

template<typename NodeT>
s11n::io::data_node_serializer<NodeT>* create_serializer const std::string &  classname  ) 
 

Returns a new instance of the given serializer class, or 0 if one could not be loaded.

e.g., register_serializer() will do the trick.

If no serializer for classname is found and classname does not contain the string "_serializer", then then (classname+"_serializer") is tried. This is intended to ease DLL lookups for the conventional abbreviations for the Serializer classes (i.e., my_serializer).

The caller owns the returned pointer, which may be 0.

Definition at line 158 of file serializers.hpp.

template<typename SerializerT>
void register_serializer const std::string &  classname,
const std::string &  alias
 

Registers a Serializer type with the s11n::io layer.

It must:

  • be templatized on a DataNodeType

  • subclass s11n::io::data_node_serializer<DataNodeType>

  • provide a node_type typedef which is the same as DataNodeType

  • Be a complete type at the time this function is called.

i.e., the conventions of all of the Serializers included with libs11n.

Registering makes the type available to the data_node_serializer classloader.

Arguments:

  • classname = SerializerT's stringified class name, minus any template parts. e.g. my_serializer.

  • alias = a "friendly" name for the SerializerT. By convention this is the Serializer's class name stripped of namespace and any trailing "_serializer" part. The alias should, by convention, be suitable to use via, e.g. entry as a command-line argument.

SerializeT's magic_cookie() function is called to alias the cookie as an alias for classname. Thus, a SerializerT object is (briefly) instantiated.

Node that this function essentially performs the same operations as the reg_serializer.hpp supermacro, and the two should be equivalent (though this seems easier to use).

Definition at line 128 of file serializers.hpp.

template<typename NodeT, typename ListT>
void serializer_list ListT &  target,
bool  onlyShortNames = true
 

Intended mainly as a convenience for client applications, serializer_list() populates the target list with the names of registered Serializers.

ListT must support push_back(std::string).

If onlyShortNames is true (the default) then only "simple" names (only alphanumeric or underscore characters) are put into target, not the "full" names of the classes. This is to make the data more useful in the context of client applications as, e.g., a list of choices for users.

When onlyShortNames is false then the list may contain some unsightly magic cookie strings.

In either case, the list may very well contain different names for the same underlying Serializer, as most are registered with several aliases.

Note that only serializers extending from s11n::io::data_node_serializer<NodeT> are returned.

The exact values returned by this function may change in the future. e.g., at the moment it does not return the "real" classnames, only registered aliases, but this is arguable behaviour and may change.

Maintenance note: i don't encourage the direc use of s11n::fac here, but that is currently the only way to get the list of class names from the factory layer.

Definition at line 51 of file serializers.hpp.


Generated on Thu Sep 29 20:01:15 2005 for libs11n-1.1.3-dev by  doxygen 1.4.1