SSAGES  0.1
A MetaDynamics Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
JSONLoaderPlugin.h
1 
26 #pragma once
27 #include <iostream>
28 #include <regex>
29 #include "FileContents.h"
30 
31 namespace SSAGES
32 {
34 
38  {
39  public:
41 
48  virtual void ApplyFilter(std::string& contents, const std::string& path) = 0;
49  };
50 
52 
56  {
57  public:
59 
66  virtual void ApplyFilter(std::string& contents, const std::string& path) override
67  {
68  std::smatch matches;
69  auto pattern = std::regex("\"@include\\((.*)\\)\"", std::regex::ECMAScript);
70  while(regex_search(contents, matches, pattern))
71  {
72  for(size_t i = 1; i < matches.size(); ++i)
73  {
74  auto content = GetFileContents((path + "/" + matches[i].str()).c_str());
75  auto rpattern = std::regex("\"@include\\(" +
76  matches[i].str() +
77  "\\)\"", std::regex::ECMAScript);
78  contents = regex_replace(contents, rpattern, content);
79  }
80  }
81  }
82 
83  };
84 }
virtual void ApplyFilter(std::string &contents, const std::string &path)=0
Apply filter to string.
Abstract class for JSON loader plugins.
Class for JSON loader include plugin.
std::string GetFileContents(const char *filename)
Read contents from a file.
Definition: FileContents.h:47
virtual void ApplyFilter(std::string &contents, const std::string &path) override
Apply filter to string.