SSAGES  0.8.3
Software Suite for Advanced General Ensemble Simulations
Public Member Functions | List of all members
SSAGES::IncludePlugin Class Reference

Class for JSON loader include plugin. More...

#include <JSONLoaderPlugin.h>

Inheritance diagram for SSAGES::IncludePlugin:
Inheritance graph
[legend]

Public Member Functions

virtual void ApplyFilter (std::string &contents, const std::string &path) override
 Apply filter to string. More...
 

Detailed Description

Class for JSON loader include plugin.

Definition at line 57 of file JSONLoaderPlugin.h.

Member Function Documentation

◆ ApplyFilter()

virtual void SSAGES::IncludePlugin::ApplyFilter ( std::string &  contents,
const std::string &  path 
)
inlineoverridevirtual

Apply filter to string.

Parameters
contentsString whose contents will be modified.
pathPath for JSON path specification.

This filter replaces @include(file.json) with contents.

Implements SSAGES::JSONLoaderPlugin.

Definition at line 68 of file JSONLoaderPlugin.h.

References SSAGES::GetFileContents().

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  }
std::string GetFileContents(const char *filename)
Read contents from a file.
Definition: FileContents.h:47
Here is the call graph for this function:

The documentation for this class was generated from the following file: