1 #ifndef CASM_QueryHandler_impl
2 #define CASM_QueryHandler_impl
15 template <
typename DataObject>
19 *
m_dict = make_dictionary<DataObject>();
26 template <
typename DataObject>
33 template <
typename DataObject>
38 template <
typename DataObject>
47 template <
typename DataObject>
50 if (m_dict->find(
"selected") != m_dict->end()) {
51 m_dict->erase(
"selected");
54 "selected", selection,
55 "Returns true if object is specified in the input selection"));
61 template <
typename DataObject>
71 template <
typename DataObject>
73 const std::string &alias_command) {
75 datum_formatter_alias<DataObject>(alias_name, alias_command, *m_dict);
76 auto key = m_dict->key(new_formatter);
79 if (m_dict->find(key) == m_dict->end()) {
80 m_dict->insert(new_formatter);
83 else if (aliases().
find(alias_name) != aliases().end()) {
84 err_log() <<
"WARNING: I already know '" << alias_name <<
"' as:\n"
85 <<
" " << _aliases()[alias_name] <<
"\n"
86 <<
" I will forget it and learn '" << alias_name
88 <<
" " << alias_command << std::endl;
89 m_dict->insert(new_formatter);
94 ss <<
"Error: Attempted to over-write standard CASM query name with user "
96 throw std::runtime_error(ss.str());
100 _aliases()[alias_name] = alias_command;
104 template <
typename DataFormatterDictInserter,
typename RuntimeLibInserter>
107 RuntimeLibInserter lib_it) {
108 typedef typename DataFormatterDictInserter::container_type dict_type;
109 typedef typename dict_type::DataObject DataObject;
110 typedef typename dict_type::DatumFormatterType formatter_type;
111 typedef formatter_type *formatter_type_ptr;
112 typedef formatter_type_ptr(signature)();
117 return std::make_pair(dict_it, lib_it);
122 for (
auto &entry : boost::make_iterator_range(
124 fs::path p = entry.path();
125 std::string p_s = p.string();
126 auto p_size = p_s.size();
128 if (fs::is_regular_file(p) &&
129 p_s.compare(p_size - 3, p_size,
".cc") == 0) {
130 fs::path f = p.filename();
131 std::string f_s = f.string();
132 auto f_size = f_s.size();
135 "compiling new custom query: " + f_s.substr(0, f_size - 3);
139 p_s.substr(0, p_size - 3),
144 auto make_formatter = lib_ptr->template get_function<signature>(
145 "make_" + f_s.substr(0, f_size - 3) +
"_formatter");
147 std::unique_ptr<formatter_type> ptr(make_formatter());
151 *lib_it++ = std::make_pair(ptr->name(), lib_ptr);
156 return std::make_pair(dict_it, lib_it);
Returns true if configuration is specified in given selection (default: MASTER)
Specification of CASM project directory structure.
fs::path root_dir() const
Return casm project directory path.
fs::path query_plugins() const
Return enumerators plugin dir.
DirectoryStructure const & dir() const
Access DirectoryStructure object. Throw if not set.
std::string compile_options() const
std::string so_options() const
QueryHandler(const ProjectSettings &set)
DataFormatterDictionary< DataObject > & dict()
std::map< std::string, std::shared_ptr< RuntimeLibrary > > m_lib
notstd::cloneable_ptr< DataFormatterDictionary< DataObject > > m_dict
void add_alias(const std::string &alias_name, const std::string &alias_command)
Add user-defined query alias.
void set_selected(const DB::Selected< DataObject > &selection)
Set the selection to be used for the 'selected' column.
std::shared_ptr< RuntimeLibrary > log_make_shared_runtime_lib(std::string filename_base, std::string compile_options, std::string so_options, std::string compile_msg)
Make shared_ptr<RuntimeLibrary>, logging progress and errors.
std::string include_path(const fs::path &dir)
Iterator find(Iterator begin, Iterator end, const T &value, BinaryCompare q)
Equivalent to std::find(begin, end, value), but with custom comparison.
std::pair< DataFormatterDictInserter, RuntimeLibInserter > load_query_plugins(const ProjectSettings &set, DataFormatterDictInserter dict_it, RuntimeLibInserter lib_it)
Load enumerator plugins from a CASM project.
Non-std smart pointer classes and functions.
cloneable_ptr< T > make_cloneable(Args &&... args)
make a cloneable_ptr<T> via T(Args... args)
DirectoryStructure const & dir