CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
EnumeratorHandler_impl.hh
Go to the documentation of this file.
3 
5 #include "casm/clex/PrimClex.hh"
8 
9 namespace CASM {
10 
29  template<typename EnumeratorMapInserter, typename RuntimeLibInserter>
30  std::pair<EnumeratorMapInserter, RuntimeLibInserter>
32  const ProjectSettings &set,
33  EnumeratorMapInserter enum_it,
34  RuntimeLibInserter lib_it) {
35 
36  const DirectoryStructure &dir = set.dir();
37 
38  if(dir.root_dir().empty()) {
39  return std::make_pair(enum_it, lib_it);
40  }
41 
42  if(fs::is_directory(dir.enumerator_plugins())) {
43 
44  // loop over custom enumerator files *.cc
45  for(auto &entry : boost::make_iterator_range(fs::directory_iterator(dir.enumerator_plugins()), {})) {
46 
47  fs::path p = entry.path();
48  std::string p_s = p.string();
49  auto p_size = p_s.size();
50 
51  if(fs::is_regular_file(p) && p_s.compare(p_size - 3, p_size, ".cc") == 0) {
52 
53  fs::path f = p.filename();
54  std::string f_s = f.string();
55  auto f_size = f_s.size();
56 
57  std::string msg = "compiling new custom enumerator: " + f_s.substr(0, f_size - 3);
58 
59  // '-L$CASM_PREFIX/.libs' is a hack so 'make check' works
60  auto lib_ptr = std::make_shared<RuntimeLibrary>(
61  p_s.substr(0, p_size - 3),
62  set.compile_options() + " " + include_path(dir.enumerator_plugins()),
63  set.so_options() + " -lcasm ",
64  msg,
65  set);
66 
67  auto make_interface = lib_ptr->get_function<EnumInterfaceBase* ()>(
68  "make_" + f_s.substr(0, f_size - 3) + "_interface");
69 
70  std::unique_ptr<EnumInterfaceBase> ptr(make_interface());
71 
72  // will clone on insert
73  *enum_it++ = *ptr;
74  *lib_it++ = std::make_pair(ptr->name(), lib_ptr);
75  }
76  }
77  }
78 
79  return std::make_pair(enum_it, lib_it);
80  }
81 
82 }
Specification of CASM project directory structure.
std::string include_path(const fs::path &dir)
std::string so_options() const
Get current shared library options string.
Base class for generic use of enumerators that may be accessed through the API.
Definition: Enumerator.hh:418
Main CASM namespace.
Definition: complete.cpp:8
ProjectSettings & set
Definition: settings.cc:103
fs::path enumerator_plugins() const
Return enumerators plugin dir.
Read/modify settings of an already existing CASM project.
fs::path root_dir() const
Return casm project directory path.
std::string compile_options() const
Get current compilation options string.
DirectoryStructure & dir
Definition: settings.cc:102
std::pair< EnumeratorMapInserter, RuntimeLibInserter > load_enumerator_plugins(const ProjectSettings &set, EnumeratorMapInserter enum_it, RuntimeLibInserter lib_it)
Load enumerator plugins from a CASM project.
const DirectoryStructure & dir() const