//////////////////////////////////////////////////////////////////////// // s11nlite.cpp: impl file for s11nlite.h // author: stephan@s11n.net // license: public domain //////////////////////////////////////////////////////////////////////// #include #include #include // ::getenv() #include #include #include #include // #include #include // create_serializer() #define S11NLITE_CONFIG_FILE std::string("${HOME}/.s11nlite-1.1.conf") #define S11NLITE_SERIALIZER_KEY std::string("serializer_class") namespace s11nlite { static client_interface * m_inst = 0; client_interface & instance() { return m_inst ? *m_inst : client_interface::instance(); } void instance( client_interface * newinst ) { m_inst = newinst; return; } /** INTERNAL. Returns a reference to s11nlite's configuration object. It is read from $HOME/.s11nlite at library startup and saved at library shutdown. s11n clients are encouraged to use their own configuration storage, but this one "may" be used by s11n-related clients (like s11nbrowser). */ node_type & config(); /** Class name of current Serializer. */ // std::string m_serializer = s11n_S11NLITE_DEFAULT_SERIALIZER_TYPE_NAME; std::string m_configfile; node_type * m_confignode = 0; struct config_saver { // when this is dtor'd config() will be saved. ~config_saver() { //CERR << "Saving s11nlite config file ["<( classname ); } serializer_interface * create_serializer() { return create_serializer( serializer_class() ); } node_type * find_child( node_type & parent, const std::string subnodename ) { return s11n::find_child_by_name( parent, subnodename ); } const node_type * find_child( const node_type & parent, const std::string subnodename ) { return s11n::find_child_by_name( parent, subnodename ); } bool save( const node_type & src, std::ostream & dest ) { return instance().save( src, dest ); } bool save( const node_type & src, const std::string & dest ) { return instance().save( src, dest ); } node_type * load_node( const std::string & src ) { return instance().load_node( src ); } node_type * load_node( std::istream & src ) { return instance().load_node( src ); } } // namespace #undef S11NLITE_CONFIG_FILE