4 #include "caffe2/core/logging.h" 12 inline std::string replace(
14 const std::string& substring,
15 const std::string& target) {
18 index = line.find(substring, index);
19 if (index == std::string::npos) {
22 line.replace(index, substring.length(), target);
23 index += substring.length();
31 inline std::vector<std::string> split(
const string& str,
const string& delim) {
32 std::vector<std::string> tokens;
33 size_t prev = 0, pos = 0;
35 pos = str.find(delim, prev);
36 if (pos == std::string::npos) {
39 std::string token = str.substr(prev, pos - prev);
41 tokens.push_back(token);
43 prev = pos + delim.length();
44 }
while (pos < str.length() && prev < str.length());
52 inline bool check_path_valid(std::string path,
bool remove =
true) {
53 CAFFE_ENFORCE(!path.empty());
54 std::ifstream file(path.c_str());
56 if (!file.good() && !
static_cast<bool>(std::ofstream(path).put(
't'))) {
61 std::remove(path.c_str());
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...