Skip to content

Commit a6eac28

Browse files
committed
Add initialization lists
1 parent 39a1851 commit a6eac28

6 files changed

+17
-36
lines changed

Calculator.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
int main(int argc, char** argv)
55
{
6-
std::string folder = "./plugins";//for Visual Studio
7-
//std::string folder = "..\\plugins";//for Cmake project
6+
//std::string folder = "./plugins";//for Visual Studio
7+
std::string folder = "..\\plugins";//for Cmake project
88
std::string extension = ".dll";
99
Calculator app(folder, extension);
1010
while (true)

Calculator.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ class Calculator
1212

1313

1414
public:
15-
Calculator(const std::string& folder, const std::string& extension)
16-
{
17-
this->parser = std::make_unique<Parser>(folder, extension);
18-
this->input = "";
19-
this->output = "";
20-
};
15+
Calculator(const std::string& folder, const std::string& extension) :
16+
parser(std::make_unique<Parser>(folder, extension)), input(""), output("") {};
17+
2118
~Calculator() = default;
2219
Calculator() = default;
2320
Calculator(const Calculator&) = default;

Loader.cpp

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "Loader.h"
22

3-
std::unique_ptr<Operator> Loader::getOperatorFromDll(const HINSTANCE& load)
3+
void Loader::getOperatorFromDll(std::map<std::string, std::unique_ptr<Operator>>& operations, const HINSTANCE& load)
44
{
55

66
std::function<double(double, double)> Operation = (double (*) (double, double))GetProcAddress(load, "operation");
@@ -9,12 +9,10 @@ std::unique_ptr<Operator> Loader::getOperatorFromDll(const HINSTANCE& load)
99
std::function<std::string(void)> Name = (std::string(*) (void)) GetProcAddress(load, "name");
1010
std::function<bool(void)> Associativity = (bool (*) (void))GetProcAddress(load, "associativity");
1111

12-
std::unique_ptr<Operator> op = std::make_unique<Operator>(Name(), Priority(), Associativity(), Binary(), Operation);
13-
14-
return op;
12+
operations[Name()] = std::move(std::make_unique<Operator>(Name(), Priority(), Associativity(), Binary(), Operation));
1513
}
1614

17-
void Loader::loadDll(std::map<std::string, std::unique_ptr<Operator>>& operation_list, const std::string& folder, const std::string& extension)
15+
void Loader::loadDll(std::map<std::string, std::unique_ptr<Operator>>& operations, const std::string& folder, const std::string& extension)
1816
{
1917
std::vector<std::filesystem::path> files;
2018

@@ -32,12 +30,8 @@ void Loader::loadDll(std::map<std::string, std::unique_ptr<Operator>>& operation
3230
this->libraries.push_back(load);
3331

3432
if (load)
35-
{
36-
std::unique_ptr<Operator> op = getOperatorFromDll(load);
37-
operation_list[op->getName()] = std::move(op);
38-
continue;
39-
}
40-
33+
getOperatorFromDll(operations, load);
34+
else
4135
std::cerr << "Opening dll file " << path << " failure" << std::endl;
4236
}
4337

Loader.h

+2-8
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ class Loader
1616
std::string extension;
1717

1818
public:
19-
Loader(const std::string& folder, const std::string& extension)
20-
{
21-
this->libraries;
22-
this->folder = folder;
23-
this->extension = extension;
24-
}
25-
19+
Loader(const std::string& folder, const std::string& extension) : libraries({}), folder(folder), extension(extension) {};
2620
Loader() = default;
2721
Loader(const Loader&) = default;
2822
Loader(Loader&&) = default;
@@ -35,7 +29,7 @@ class Loader
3529
FreeLibrary(lib);
3630
libraries.clear();
3731
}
38-
std::unique_ptr<Operator> getOperatorFromDll(const HINSTANCE& load);
32+
void getOperatorFromDll(std::map<std::string, std::unique_ptr<Operator>>& operations, const HINSTANCE& load);
3933
void loadDll(std::map<std::string, std::unique_ptr<Operator>>& operations, const std::string& folder, const std::string& extension);
4034

4135
};

Operations.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Operations
2626
this->loader.loadDll(this->operations, folder, extension);
2727
}
2828
else
29-
std::cout << std::endl << "Folder for extra operations is not download" << std::endl;
29+
std::cerr << std::endl << "Folder for extra operations is not download" << std::endl;
3030
};
3131

3232
int getPriority(const std::string& symbol);

Operator.h

+4-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88
class Operator
99
{
1010
public:
11-
Operator(const std::string& name, int priority, bool associativity, int binary, std::function<double(double, double)> operation)
12-
{
13-
this->name = name;
14-
this->priority = priority;
15-
this->operation = operation;
16-
this->associativity = associativity;
17-
this->binary = binary;
18-
}
11+
Operator(const std::string& name, int priority, bool associativity,
12+
int binary, const std::function<double(double, double)>& operation)
13+
: name(name), priority(priority), associativity(associativity), binary(binary), operation(operation) {};
14+
1915
Operator() = default;
2016
~Operator() = default;
2117
Operator(const Operator& A) = default;

0 commit comments

Comments
 (0)