WebFramework v3.0.12
Web framework for C++.
Loading...
Searching...
No Matches
StandardWebFrameworkDynamicPagesFunctions.cpp
1#include "StandardWebFrameworkDynamicPagesFunctions.h"
2
3#include "Exceptions/FileDoesNotExistException.h"
4
5using namespace std;
6
7namespace framework
8{
9 string print(const vector<string>& arguments)
10 {
11 string result;
12
13 for (const auto& i : arguments)
14 {
15 result += i + ' ';
16 }
17
18 result.pop_back();
19
20 return result;
21 }
22
23 string include(const vector<string>& arguments, const string& pathToTemplates)
24 {
25 string result;
26 string tem;
27 const filesystem::path filePath(pathToTemplates + '/' + arguments[0]);
28
29 if (!filesystem::exists(filePath))
30 {
31 throw file_manager::exceptions::FileDoesNotExistException(filePath.string());
32 }
33
34 result.reserve(filesystem::file_size(filePath));
35
36 ifstream in(filePath);
37
38 while (getline(in, tem))
39 {
40 result += tem + '\n';
41 }
42
43 in.close();
44
45 return result;
46 }
47
48 string forWFDP(const vector<string>& arguments, const unordered_map<string, function<string(const vector<string>&)>>& dynamicPagesFunctions)
49 {
50 int64_t start = stoll(arguments[0]);
51 int64_t end = stoll(arguments[1]);
52 const function<string(const vector<string>&)> repeatableFunction = dynamicPagesFunctions.at(arguments[2]);
53 int64_t step = 1;
54 string result;
55
56 if (arguments.size() == 4)
57 {
58 step = stoll(arguments[3]);
59 }
60
61 for (int64_t i = start; i < end; i += step)
62 {
63 result += repeatableFunction({ to_string(i) });
64 }
65
66 return result;
67 }
68}