Skip to content

Commit 116c480

Browse files
committed
Delete flags and rename variables
1 parent a6eac28 commit 116c480

8 files changed

+128
-185
lines changed

CMakeLists.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,5 @@ project ("Calculator")
99
add_executable (Calculator "Calculator.cpp" "Calculator.h" "Operator.h" "Loader.h" "Loader.cpp" "Operations.h" "Operations.cpp" "Parser.h" "Parser.cpp")
1010

1111

12-
configure_file(${PROJECT_SOURCE_DIR}/plugins/DynamicLib4.dll ${PROJECT_BINARY_DIR}/plugins/DynamicLib4.dll COPYONLY)
13-
configure_file(${PROJECT_SOURCE_DIR}/plugins/DynamicLib5.dll ${PROJECT_BINARY_DIR}/plugins/DynamicLib5.dll COPYONLY)
14-
configure_file(${PROJECT_SOURCE_DIR}/plugins/DynamicLib6.dll ${PROJECT_BINARY_DIR}/plugins/DynamicLib6.dll COPYONLY)
12+
file(COPY "${PROJECT_SOURCE_DIR}/plugins" DESTINATION "${CMAKE_BINARY_DIR}")
1513
# TODO: Добавьте тесты и целевые объекты, если это необходимо.

Calculator.h

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef CALCULATOR_H
2-
#define CALCULATOR_H
1+
#pragma once
32

43
#include "Parser.h"
54

@@ -10,28 +9,20 @@ class Calculator
109
std::string input;
1110
std::string output;
1211

13-
1412
public:
1513
Calculator(const std::string& folder, const std::string& extension) :
1614
parser(std::make_unique<Parser>(folder, extension)), input(""), output("") {};
1715

1816
~Calculator() = default;
19-
Calculator() = default;
20-
Calculator(const Calculator&) = default;
21-
Calculator(Calculator&&) = default;
22-
Calculator& operator=(Calculator const&) = default;
23-
Calculator& operator=(Calculator&&) = default;
2417

25-
void setInput(const std::string& input)
18+
void setInput(const std::string& input_)
2619
{
27-
this->input = input;
20+
input = input_;
2821
}
2922
void calculation()
3023
{
31-
if (this->parser->shuntingYard(this->input, this->output))
32-
this->parser->executionOrder(this->output);
24+
if (parser->parse(this->input, this->output))
25+
parser->evaluate(this->output);
3326
}
3427

3528
};
36-
37-
#endif

Loader.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ void Loader::loadDll(std::map<std::string, std::unique_ptr<Operator>>& operation
2727
{
2828
widecFileName = path.c_str();
2929
load = LoadLibraryW(widecFileName);
30-
this->libraries.push_back(load);
31-
30+
3231
if (load)
32+
{
33+
this->libraries.push_back(load);
3334
getOperatorFromDll(operations, load);
35+
}
3436
else
35-
std::cerr << "Opening dll file " << path << " failure" << std::endl;
37+
std::cerr << "Opening dll file " << path << " failure" << std::endl;
3638
}
3739

3840
}

Loader.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef LOADER_H
2-
#define LOADER_H
1+
#pragma once
32

43
#include <Windows.h>
54
#include <map>
@@ -18,10 +17,6 @@ class Loader
1817
public:
1918
Loader(const std::string& folder, const std::string& extension) : libraries({}), folder(folder), extension(extension) {};
2019
Loader() = default;
21-
Loader(const Loader&) = default;
22-
Loader(Loader&&) = default;
23-
Loader& operator=(Loader const&) = default;
24-
Loader& operator=(Loader&&) = default;
2520

2621
~Loader()
2722
{
@@ -33,5 +28,3 @@ class Loader
3328
void loadDll(std::map<std::string, std::unique_ptr<Operator>>& operations, const std::string& folder, const std::string& extension);
3429

3530
};
36-
37-
#endif

Operations.h

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
#ifndef OPERATIONS_H
2-
#define OPERATIONS_H
1+
#pragma once
32

43
#include "Loader.h"
54

65
class Operations
76
{
7+
8+
private:
9+
std::map<std::string, std::unique_ptr<Operator>> operations;
10+
Loader loader;
811
public:
912
Operations()
1013
{
11-
this->operations["+"] = std::make_unique<Operator>("+", 1, true, 2, [](double a, double b) { return a + b; });
12-
this->operations["-"] = std::make_unique<Operator>("-", 1, true, 2, [](double a, double b) { return a - b; });
13-
this->operations["*"] = std::make_unique<Operator>("*", 2, true, 2, [](double a, double b) { return a * b; });
14-
this->operations["/"] = std::make_unique<Operator>("/", 2, true, 2, [](double a, double b) {
14+
operations["+"] = std::make_unique<Operator>("+", 1, true, 2, [](double a, double b) { return a + b; });
15+
operations["-"] = std::make_unique<Operator>("-", 1, true, 2, [](double a, double b) { return a - b; });
16+
operations["*"] = std::make_unique<Operator>("*", 2, true, 2, [](double a, double b) { return a * b; });
17+
operations["/"] = std::make_unique<Operator>("/", 2, true, 2, [](double a, double b) {
1518
if (b)
1619
return a / b;
1720
std::cerr << std::endl << "Unavaliable operation: Division by zero" << std::endl;
1821
return a; });
19-
this->loader = Loader();
22+
loader = Loader();
2023
};
2124
Operations(const std::string& folder, const std::string& extension) : Operations()
2225
{
2326
if (folder != "" && extension != "")
2427
{
25-
this->loader = Loader(folder, extension);
26-
this->loader.loadDll(this->operations, folder, extension);
28+
loader = Loader(folder, extension);
29+
loader.loadDll(this->operations, folder, extension);
2730
}
2831
else
2932
std::cerr << std::endl << "Folder for extra operations is not download" << std::endl;
@@ -40,9 +43,4 @@ class Operations
4043
Operations& operator = (const Operations& A) = default;
4144
Operations& operator=(Operations&&) = default;
4245

43-
private:
44-
std::map<std::string, std::unique_ptr<Operator>> operations;
45-
Loader loader;
4646
};
47-
48-
#endif

Operator.h

+14-22
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,46 @@
11
#pragma once
2-
#ifndef OPERATOR_H
3-
#define OPERATOR_H
42

53
#include <iostream>
64
#include <functional>
75

86
class Operator
97
{
8+
private:
9+
std::string name;
10+
int priority;
11+
bool associativity;// true - left, false - right
12+
int binary;
13+
std::function<double(double, double)> operation;
14+
1015
public:
1116
Operator(const std::string& name, int priority, bool associativity,
1217
int binary, const std::function<double(double, double)>& operation)
1318
: name(name), priority(priority), associativity(associativity), binary(binary), operation(operation) {};
14-
15-
Operator() = default;
1619
~Operator() = default;
17-
Operator(const Operator& A) = default;
18-
Operator(Operator&&) = default;
19-
Operator& operator = (const Operator& A) = default;
20-
Operator& operator=(Operator&&) = default;
2120

2221
int getPriority()
2322
{
24-
return this->priority;
23+
return priority;
2524
}
2625
std::string getName()
2726
{
28-
return this->name;
27+
return name;
2928
}
3029
int getBinary()
3130
{
32-
return this->binary;
31+
return binary;
3332
}
3433
bool getAssociativity()
3534
{
36-
return this->associativity;
35+
return associativity;
3736
}
3837
std::function<double(double, double)> getOperation()
3938
{
40-
return this->operation;
39+
return operation;
4140
}
4241
double calculation(double a, double b)
4342
{
44-
return (this->operation)(a, b);
43+
return (operation)(a, b);
4544
}
46-
private:
47-
std::string name;
48-
int priority;
49-
bool associativity;// true - left, false - right
50-
int binary;
51-
std::function<double(double, double)> operation;
52-
};
5345

54-
#endif
46+
};

0 commit comments

Comments
 (0)