1#include "base_provider.h"
2#include "base_provider_generator.h"
3#include <cgv/gui/trigger.h>
4#include <cgv/utils/file.h>
6#include <cgv/utils/tokenizer.h>
22 return "base_provider_generator";
42std::string error_start(
const std::string& content,
const token& T)
44 std::string error(
"error (");
45 const char* end = T.end;
46 if (&content[content.size()-1] < end)
47 end = &content[content.size()-1];
50 for (
const char* p = &content[0]; p<end;++p)
59void base_provider_generator::timer_event(
double,
double)
61 for (std::map<std::string,long long>::const_iterator i =
gui_files.begin(); i !=
gui_files.end(); ++i) {
62 long long lwt = cgv::utils::file::get_last_write_time(i->first);
72 if (!cgv::utils::file::read(file_name, content,
true))
74 gui_files[file_name] = cgv::utils::file::get_last_write_time(file_name);
78 while (i < T.size()) {
80 if (!((is_type = (T[i] ==
"type")) || T[i] ==
"name")) {
81 std::cerr << error_start(content, T[i]) <<
"expected type or name" << std::endl;
85 if (++i >= T.size()) {
86 std::cerr << error_start(content, T[i-1]) <<
"incomplete definition" << std::endl;
90 std::cerr << error_start(content, T[i]) <<
"expected ( " << std::endl;
93 if (++i >= T.size()) {
94 std::cerr << error_start(content, T[i-1]) <<
"incomplete definition" << std::endl;
97 if (T[i] ==
")" || T[i] ==
"{" || T[i] ==
"}" || T[i] ==
":") {
98 std::cerr << error_start(content, T[i]) <<
"unexpected token" << std::endl;
102 if (++i >= T.size()) {
103 std::cerr << error_start(content, T[i-1]) <<
"incomplete definition" << std::endl;
107 std::cerr << error_start(content, T[i]) <<
"expected )" << std::endl;
110 if (++i >= T.size()) {
111 std::cerr << error_start(content, T[i-1]) <<
"incomplete definition" << std::endl;
116 if (++i >= T.size()) {
117 std::cerr << error_start(content, T[i-1]) <<
"incomplete definition" << std::endl;
124 std::cerr << error_start(content, T[i]) <<
"expected {" << std::endl;
129 while (j < T.size()) {
132 else if (T[j] ==
"}") {
141 std::cerr << error_start(content, T[j-1]) <<
"missing }" << std::endl;
142 end_ptr = &content[content.size()];
145 end_ptr = T[j-1].end;
147 std::string def(T[i+1].begin, end_ptr-T[i+1].begin);
153 if (!pi->second->is_named_gui_assignment() && pi->first->get_type_name() == key)
154 pi->second->set_gui_definition(def);
155 pi->second->multi_set(options,
true);
163 if (pi->first->get_named() && pi->first->get_named()->get_name() == key) {
164 pi->second->set_gui_definition(def);
165 pi->second->multi_set(options,
true);
166 pi->second->set_named_gui_assignment(
true);
186 if (object->get_named()) {
187 const std::string& name =
object->get_named()->get_name();
191 if (!iter->second.options.empty())
192 pvd->multi_set(iter->second.options,
true);
201 if (!iter->second.options.empty())
202 pvd->multi_set(iter->second.options,
true);
213 if (object->get_interface<
provider>())
More advanced text processing for splitting text into lines or tokens.
bool generate_object_gui(cgv::base::base_ptr object)
check whether gui description is available for object and if yes generate a base_provider
def_map_type defs_by_type
mappings from type to gui definitions
bool parse_gui_file(const std::string &file_name)
parse file and extract gui definitions
def_map_type::const_iterator def_map_iter
iterator type for map
def_map_type defs_by_name
mappings from name to gui definitions
pvd_map_type providers
store map to base_providers
void register_object(cgv::base::base_ptr object, const std::string &options)
if object is registered that does not provide its own gui but matches type or name of a parsed gui de...
void unregister_object(cgv::base::base_ptr object, const std::string &options)
remove also the base_provider of an object if created
bool self_reflect(cgv::reflect::reflection_handler &rh)
used for simple self reflection
void on_set(void *member_ptr)
this callback is called when the set_void method has changed a member and can be overloaded in derive...
std::vector< cgv::base::base_ptr > unmatched_objects
keep track of unmatched objects
base_provider_generator()
construct from instance and gui definition
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...
std::map< std::string, long long > gui_files
store read gui files with last write times
bool check_file_update
whether to check files
pvd_map_type::iterator pvd_map_iter
iterator type of base_provider map
derive from this class to provide a gui to the current viewer
the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base.
bool reflect_member(const std::string &member_name, T &member_ref, bool hard_cast=false)
call this to reflect a member by member name and reference to the member.
the tokenizer allows to split text into tokens in a convenient way.
tokenizer & set_sep(const std::string &sep, bool merge)
set the list of separators and specify whether succeeding separators are merged into single tokens
tokenizer & set_skip(const std::string &open, const std::string &close)
set several character pairs that enclose tokens that are not split
void unregister_object(base_ptr object, const std::string &options)
unregister an object and send event to all current registration ref_listeners()
void register_object(base_ptr object, const std::string &options)
register an object and send event to all current registration ref_listeners()
trigger & get_animation_trigger()
return the global trigger used for animation, which runs by default with 60 Hz
namespace that holds tools that dont fit any other namespace
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
this header is dependency free
each gui definition consists of the textual definition as well as an options string
representation of a token in a text by two pointers begin and end, that point to the first character ...