CASM  1.1.0
A Clusters Approach to Statistical Mechanics
EnumeratorHandler_impl.hh
Go to the documentation of this file.
1 #include <boost/filesystem.hpp>
2 
11 
12 namespace CASM {
13 
34 template <typename EnumInterfaceVectorInserter, typename RuntimeLibInserter>
35 std::pair<EnumInterfaceVectorInserter, RuntimeLibInserter>
37  EnumInterfaceVectorInserter enum_it,
38  RuntimeLibInserter lib_it) {
39  const DirectoryStructure &dir = set.dir();
40 
41  if (dir.root_dir().empty()) {
42  return std::make_pair(enum_it, lib_it);
43  }
44 
45  if (fs::is_directory(dir.enumerator_plugins())) {
46  // loop over custom enumerator files *.cc
47  for (auto &entry : boost::make_iterator_range(
48  fs::directory_iterator(dir.enumerator_plugins()), {})) {
49  fs::path p = entry.path();
50  std::string p_s = p.string();
51  auto p_size = p_s.size();
52 
53  if (fs::is_regular_file(p) &&
54  p_s.compare(p_size - 3, p_size, ".cc") == 0) {
55  fs::path f = p.filename();
56  std::string f_s = f.string();
57  auto f_size = f_s.size();
58 
59  std::string msg =
60  "compiling new custom enumerator: " + f_s.substr(0, f_size - 3);
61 
62  auto lib_ptr = log_make_shared_runtime_lib(
63  p_s.substr(0, p_size - 3),
64  set.compile_options() + " " +
66  set.so_options() + " -lcasm ", msg);
67 
68  auto make_interface = lib_ptr->get_function<EnumInterfaceBase *()>(
69  "make_" + f_s.substr(0, f_size - 3) + "_interface");
70 
71  notstd::cloneable_ptr<EnumInterfaceBase> ptr(make_interface());
72 
73  std::string method_name = ptr->name();
74  *enum_it++ = std::move(ptr);
75  *lib_it++ = std::make_pair(method_name, lib_ptr);
76  }
77  }
78  }
79 
80  return std::make_pair(enum_it, lib_it);
81 }
82 
83 } // namespace CASM
Specification of CASM project directory structure.
fs::path root_dir() const
Return casm project directory path.
fs::path enumerator_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
A 'cloneable_ptr' can be used in place of 'unique_ptr'.
Main CASM namespace.
Definition: APICommand.hh:8
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::pair< EnumInterfaceVectorInserter, RuntimeLibInserter > load_enumerator_plugins(ProjectSettings const &set, EnumInterfaceVectorInserter enum_it, RuntimeLibInserter lib_it)
Load enumerator plugins from a CASM project.
std::string include_path(const fs::path &dir)
DirectoryStructure const & dir
Definition: settings.cc:136
ProjectSettings & set
Definition: settings.cc:137