SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
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  virtual ~JSONLoaderPlugin() = default;
51  };
52 
54 
58  {
59  public:
61 
68  virtual void ApplyFilter(std::string& contents, const std::string& path) override
69  {
70  std::smatch matches;
71  auto pattern = std::regex("\"@include\\((.*)\\)\"", std::regex::ECMAScript);
72  while(regex_search(contents, matches, pattern))
73  {
74  for(size_t i = 1; i < matches.size(); ++i)
75  {
76  auto content = GetFileContents((path + "/" + matches[i].str()).c_str());
77  auto rpattern = std::regex("\"@include\\(" +
78  matches[i].str() +
79  "\\)\"", std::regex::ECMAScript);
80  contents = regex_replace(contents, rpattern, content);
81  }
82  }
83  }
84 
85  };
86 }
Class for JSON loader include plugin.
virtual void ApplyFilter(std::string &contents, const std::string &path) override
Apply filter to string.
Abstract class for JSON loader plugins.
virtual void ApplyFilter(std::string &contents, const std::string &path)=0
Apply filter to string.
std::string GetFileContents(const std::string filename)
Read contents from a file.
Definition: FileContents.h:46