3 #include <cgv/base/base.h>
4 #include <cgv/base/named.h>
5 #include <cgv/utils/token.h>
6 #include <cgv/type/info/type_name.h>
11 #include "lib_begin.h"
44 extern void CGV_API
define_registration_order(
const std::string& partial_order,
bool before_contructor_execution =
false,
const std::string& when =
"always");
49 registration_order_definition(
const std::string& partial_order,
bool before_contructor_execution =
false,
const std::string& when =
"always");
120 template <
class T,
typename CA>
121 class object_constructor_impl_1 :
public object_constructor
127 object_constructor_impl_1(
const CA& _ca) : ca(_ca) {}
137 template <
class T,
typename CA1,
typename CA2>
138 class object_constructor_impl_2 :
public object_constructor
145 object_constructor_impl_2(
const CA1& _ca1,
const CA2& _ca2) : ca1(_ca1), ca2(_ca2) {}
168 template <
class T,
typename CA>
181 template <
class T,
typename CA1,
typename CA2>
237 factory(
const std::string& _created_type_name,
bool _singleton =
false,
const std::string& _object_options =
"");
239 virtual std::string get_object_options()
const;
241 const std::string& get_created_type_name()
const;
243 std::string get_property_declarations();
245 bool set_void(
const std::string& property,
const std::string& value_type,
const void* value_ptr);
247 bool get_void(
const std::string& property,
const std::string& value_type,
void* value_ptr);
249 bool is_singleton_factory()
const;
253 void release_singleton();
264 inline factory_impl(
const std::string& _created_type_name,
bool _is_singleton =
false,
const std::string& _object_options =
"") :
265 factory(_created_type_name, _is_singleton, _object_options) {}
271 template <
class T,
typename CA>
275 inline factory_impl_1(CA _ca,
const std::string& _created_type_name,
bool is_singleton =
false,
const std::string& _object_options =
"") :
282 template <
class T,
typename CA1,
typename CA2>
287 inline factory_impl_2(CA1 _ca1, CA2 _ca2,
const std::string& _created_type_name,
bool is_singleton =
false,
const std::string& _object_options =
"") :
293 extern std::string CGV_API guess_created_type_name(
const char* item_text);
294 extern void CGV_API register_factory_object(
base_ptr fo,
const char* item_text,
char shortcut);
308 factory_registration(
const std::string& _created_type_name,
const std::string& _options =
"",
bool _is_singleton =
false,
const std::string& _object_options =
"") {
315 register_factory_object(
new factory_impl<T>(guess_created_type_name(item_text), is_singleton), item_text, shortcut);
320 template <
class T,
typename CA>
331 factory_registration_1(
const std::string& _created_type_name,
const CA& _ca,
const std::string& _options =
"",
bool _is_singleton =
false,
const std::string& _object_options =
"") {
338 register_factory_object(
new factory_impl_1<T,CA>(_ca, guess_created_type_name(item_text), is_singleton), item_text, shortcut);
343 template <
class T,
typename CA1,
typename CA2>
354 factory_registration_2(
const std::string& _created_type_name,
const CA1& _ca1,
const CA2& _ca2,
const std::string& _options =
"",
bool _is_singleton =
false,
const std::string& _object_options =
"") {
365 class CGV_API test :
public base
378 test(
const std::string& _test_name,
bool (*_test_func)());
380 std::string get_type_name()
const;
382 std::string get_test_name()
const;
384 bool exec_test()
const;
388 #define TEST_ASSERT(V) \
390 std::cerr << "\n" << __FILE__ << "(" << __LINE__ << ") : error: test failure" << std::endl; \
391 ++cgv::base::test::nr_failed; \
395 #define TEST_ASSERT_EQ(V,Q) \
397 std::cerr << "\n" << __FILE__ << "(" << __LINE__ << ") : error: test failure " << (V) << "!=" << (Q) << std::endl; \
398 ++cgv::base::test::nr_failed; \
427 unsigned int _file_offset = 0,
428 unsigned int _file_length = 0,
429 const char* _file_data = 0,
430 const std::string& _source_file =
"");
437 extern CGV_API
void register_resource_file(
const std::string& file_path,
unsigned int file_offset,
unsigned int file_length,
const char* file_data,
const std::string& source_file =
"");
519 extern bool CGV_API
process_command(
const std::string& cmd,
bool eliminate_quotes =
true);
579 extern CGV_API
void*
load_plugin(
const std::string& file_name);
590 #include <cgv/config/lib_end.h>
interface for a factory that allows to create objects derived from cgv::base::base
Definition: register.h:225
abstract interface for a config file driver that handles permanent registration and gui config files.
Definition: register.h:553
void disable_permanent_registration()
deregister registration listener and dereference pointers to registered objects
Definition: register.cxx:507
bool is_registration_enabled()
check whether registration is enabled
Definition: register.cxx:473
std::string object_options
store the options used for registering newly created objects
Definition: register.h:234
object_registration(const std::string &options)
pass information about the target registration listener in the options argument
Definition: register.h:159
convenience class to register an object of the given class type with one constructor argument
Definition: register.h:170
a structure to store an analized command
Definition: register.h:484
std::string get_type_name() const
overload to return the type name of this object. By default the type interface is queried over get_ty...
Definition: register.h:278
convenience class to register an object of the given class type
Definition: register.h:157
bool unload_plugin(void *handle)
unload the plugin with the given handle
Definition: register.cxx:1435
factory_registration(const std::string &_created_type_name, const std::string &_options="", bool _is_singleton=false, const std::string &_object_options="")
this registers an instance of the default factory implementation
Definition: register.h:308
virtual config_file_observer * find_config_file_observer(const std::string &file_name, const std::string &content)=0
create or find a config_file_observer from the given file name and the read content of the config fil...
static int nr_failed
static counter for all tests
Definition: register.h:370
void show_all()
show information about all registered members
Definition: register.cxx:936
bool is_registration_event_cleanup_enabled()
return whether registration cleanup is enabled
Definition: register.cxx:551
implementation of factory for objects of type T using a constructor with one argument of type CA
Definition: register.h:273
void enable_registration_debugging()
enable registration debugging
Definition: register.cxx:361
std::string get_type_name() const
overload to return the type name of this object. By default the type interface is queried over get_ty...
Definition: register.h:290
factory_registration_1(const std::string &_created_type_name, const CA &_ca, const std::string &_options="", bool _is_singleton=false, const std::string &_object_options="")
this registers an instance of a standard factory implementation
Definition: register.h:331
convenience class to register a factory of the given class type that uses a constructor with one argu...
Definition: register.h:322
helper class whose constructor calls the define_registration_order() function
Definition: register.h:48
convenience class to register an object of the given class type with two constructor arguments
Definition: register.h:183
interface for objects that process unknown command line arguments
Definition: register.h:461
bool is_registration_debugging_enabled()
check whether registration debugging is enabled
Definition: register.cxx:372
information registered with each resource file
Definition: register.h:416
bool process_command(const command_info &info)
process a command given by a command info structure, return whether command was processed correctly
Definition: register.cxx:1251
virtual std::string get_constructed_type_name() const =0
return the type name of the to be constructed object
convenience class to register a resource file
Definition: register.h:441
virtual base_ptr create_object_impl()=0
overload to create an object
void define_registration_order(const std::string &partial_order, bool before_contructor_execution, const std::string &when)
specify a partial order of objects for registration
Definition: register.cxx:248
base_ptr create_object_impl()
overload to create an object
Definition: register.h:266
data::ref_ptr< base, true > base_ptr
ref counted pointer to base
Definition: base.h:37
object_registration_2(const CA1 &a1, const CA2 &a2, const std::string &options="")
pass information about the target registration listener in the options argument
Definition: register.h:185
static const char * get_name()
return special name for standard types or type name from RTTI cleaned from keywords for all other typ...
Definition: type_name.h:56
virtual bool process_gui_file(const std::string &file_name)=0
process a gui file
void enable_registration_event_cleanup()
Enable cleanup of registration events (default).
Definition: register.cxx:523
std::map< std::string, resource_file_info > & ref_resource_file_map()
return a reference to a mapping of resource file names to resource file infos
Definition: register.cxx:140
virtual void multi_observe(base_ptr bp, const std::string &property_assignments, size_t off)=0
to be implemented method that adds permanent registration for a list of property assignments
declare an instance of test_registration as static variable in order to register a test function in a...
Definition: register.h:403
void unregister_all_objects()
unregister all existing objects to clean up
Definition: register.cxx:488
base_ptr get_permanently_registered_object(unsigned i)
access to i-th permanently registered object
Definition: register.cxx:500
std::string test_name
name of test function
Definition: register.h:373
base_ptr singleton
pointer to the single object created by the factory in case is_singleton is true
Definition: register.h:232
abstract interface for observers of config files.
Definition: register.h:545
unsigned get_nr_permanently_registered_objects()
access to number of permanently registered objects
Definition: register.cxx:494
factory_registration(const char *item_text, char shortcut, bool is_singleton=false)
this constructor is only provided for downward compatibility and should not be used anymore.
Definition: register.h:314
abstract base class of helpers to perform delayed registration and creation of objects in case that t...
Definition: register.h:96
convenience class to register a resource string
Definition: register.h:451
const std::string & get_created_type_name() const
overload to return the type name of the objects that the factory can create
Definition: register.cxx:846
convenience class to register a factory of the given class type that uses a constructor with one argu...
Definition: register.h:345
void process_command_line_args(int argc, char **argv)
process the command line arguments: extract program name and load all plugins
Definition: register.cxx:1265
std::string & ref_plugin_name()
return a reference to the currently loaded plugin
Definition: register.cxx:134
std::string created_type_name
store the type name of the to be created objects
Definition: register.h:228
structure used to register a test function
Definition: register.h:367
const char * file_data
pointer to
Definition: register.h:422
std::string get_type_name() const
overload to return the type name of this object. By default the type interface is queried over get_ty...
Definition: register.h:267
bool is_singleton
store whether the factory can only create one object
Definition: register.h:230
base_ptr create_object_impl()
overload to create an object
Definition: register.h:277
implementation of factory for objects of type T using the standard constructor
Definition: register.h:263
void disable_registration()
if registration is disable, all registration events are stored and sent at the momement when registra...
Definition: register.cxx:461
factory_registration_2(const std::string &_created_type_name, const CA1 &_ca1, const CA2 &_ca2, const std::string &_options="", bool _is_singleton=false, const std::string &_object_options="")
this registers an instance of a standard factory implementation
Definition: register.h:354
virtual void handle_args(std::vector< std::string > &args)=0
this function is called on registered objects with the list of unknown command line parameters
base_ptr find_object_by_type(const std::string &type_name)
in case permanent registration is active, look for a registered object by type name
Definition: register.cxx:636
void unregister_object(base_ptr object, const std::string &options)
unregister an object and send event to all current registration ref_listeners()
Definition: register.cxx:594
void disable_registration_debugging()
disable registration debugging
Definition: register.cxx:366
void register_resource_string(const std::string &string_name, const char *string_data)
register a resource string
Definition: register.cxx:919
virtual void unregister_object(base_ptr object, const std::string &options="")=0
overload to handle unregistration events
interfaces that add several listeners and objects.
Definition: register.h:208
interfaces that add provides very basic functionality.
Definition: register.h:201
bool is_permanent_registration_enabled()
check whether permanent registration is enabled
Definition: register.cxx:518
bool process_config_file(const std::string &_file_name)
interpret a config file
Definition: register.cxx:756
std::string & ref_prog_name()
return a refence to the name of the started executable
Definition: register.cxx:122
std::vector< cgv::utils::token > parameters
the parameters, one file name parameter for PLUGIN, CONFIG, GUI and two parameters (name/type,...
Definition: register.h:488
void register_resource_file(const std::string &file_path, unsigned int file_offset, unsigned int file_length, const char *file_data, const std::string &source_file)
register a resource file
Definition: register.cxx:914
factory_registration_1(const char *item_text, char shortcut, const CA &_ca, bool is_singleton=false)
this constructor is only provided for downward compatibility and should not be used anymore.
Definition: register.h:337
convenience class to register a factory of the given class type
Definition: register.h:299
virtual void register_object(base_ptr object, const std::string &options="")=0
overload to handle registration events
std::string source_file
name of
Definition: register.h:424
std::string & ref_prog_path_prefix()
return a refence to the path prefix of the started executable, this can be prepended for example to d...
Definition: register.cxx:128
void disable_registration_event_cleanup()
disable cleanup of registration events (see enable_registration_event_cleanup).
Definition: register.cxx:541
named_ptr find_object_by_name(const std::string &name)
in case permanent registration is active, look for a registered object by name
Definition: register.cxx:630
CommandType command_type
the command type
Definition: register.h:486
CommandType analyze_command(const cgv::utils::token &cmd, bool eliminate_quotes, command_info *info_ptr)
parse a command and optionally store result in the command info, returns the command type
Definition: register.cxx:974
virtual base_ptr construct_object() const =0
creation function
CommandType
enumerate type for all command types supported in configuration files
Definition: register.h:468
void enable_registration()
enable registration and send all registration events that where emitted during disabled registration
Definition: register.cxx:377
void * load_plugin(const std::string &file_name)
load a plugin or dll and return a handle to the plugin, or 0 if loading was not successful.
Definition: register.cxx:1384
unsigned int file_length
length of the resource file in bytes
Definition: register.h:420
const char * get_type_name(TypeId tid)
function that returns the name of a type specified through TypeId
Definition: type_id.cxx:117
bool process_gui_file(const std::string &file_name)
interpret a gui file
Definition: register.cxx:762
void register_config_file_driver(config_file_driver *cfd)
method to register a config_file_driver
Definition: register.cxx:661
void enable_permanent_registration()
register a registration listener that stores pointers to all registered objects
Definition: register.cxx:478
object_registration_1(const CA &arg, const std::string &options="")
pass information about the target registration listener in the options argument
Definition: register.h:172
base_ptr create_object_impl()
overload to create an object
Definition: register.h:289
void register_prog_name(const char *_prog_name)
set the file name of the current program.
Definition: register.cxx:895
void register_object(base_ptr object, const std::string &options)
register an object and send event to all current registration ref_listeners()
Definition: register.cxx:557
the cgv namespace
Definition: vr_calib.cxx:9
interfaces that allows to listen to registration events.
Definition: register.h:216
std::string get_type_name() const
return the type name of the object constructor class
Definition: register.h:99
factory(const std::string &_created_type_name, bool _singleton=false, const std::string &_object_options="")
construct
Definition: register.cxx:801
implementation of factory for objects of type T using a constructor with two arguments of types CA1 a...
Definition: register.h:284
Definition: type_name.h:54
unsigned int file_offset
at which location the resource file starts within the executable or dll
Definition: register.h:418