11 #ifndef META_MAKE_INDEX_H_
12 #define META_MAKE_INDEX_H_
15 #include "caching/all.h"
59 template <
class Index,
class... Args>
60 std::shared_ptr<Index>
make_index(
const std::string& config_file,
63 auto config = cpptoml::parse_file(config_file);
66 if (!(config.contains(
"forward-index")
67 && config.contains(
"inverted-index")))
69 throw typename Index::exception{
70 "forward-index or inverted-index missing from configuration file"};
74 auto fwd_name = config.get_as<std::string>(
"forward-index");
75 auto inv_name = config.get_as<std::string>(
"inverted-index");
77 if (*fwd_name == *inv_name)
79 throw typename Index::exception{
80 "forward and inverted index names must be different!"};
85 std::shared_ptr<Index>{
new Index(config, std::forward<Args>(args)...)};
88 if (filesystem::make_directory(idx->index_name()) && idx->valid())
91 idx->create_index(config_file);
115 template <
class Index,
template <
class,
class>
class Cache,
class... Args>
116 std::shared_ptr<cached_index<Index, Cache>>
119 return make_index<cached_index<Index, Cache>>(config_file,
120 std::forward<Args>(args)...);