Operations and AccountOperations boilerplate
This commit is contained in:
parent
94e63e8f76
commit
287f9f4751
@ -4,4 +4,4 @@ project(budget)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
add_executable(${PROJECT_NAME} src/main.cpp
|
||||
src/optHandlers/mainOptHandler.h src/optHandlers/mainOptHandler.cpp)
|
||||
src/optHandlers/mainOptHandler.h src/optHandlers/mainOptHandler.cpp src/optHandlers/operation.cpp src/optHandlers/operation.h src/optHandlers/accountOperation.cpp src/optHandlers/accountOperation.h)
|
||||
|
15
src/optHandlers/accountOperation.cpp
Normal file
15
src/optHandlers/accountOperation.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
//
|
||||
// Created by quentin on 1/17/23.
|
||||
//
|
||||
|
||||
#include "accountOperation.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
using namespace Budget::OptHandlers;
|
||||
|
||||
void AccountOperation::commit() {
|
||||
//TODO This function will be called when the action needs to be done
|
||||
}
|
||||
|
||||
AccountOperation::AccountOperation() = default;
|
31
src/optHandlers/accountOperation.h
Normal file
31
src/optHandlers/accountOperation.h
Normal file
@ -0,0 +1,31 @@
|
||||
//
|
||||
// Created by quentin on 1/17/23.
|
||||
//
|
||||
|
||||
#ifndef BUDGET_ACCOUNTOPERATION_H
|
||||
#define BUDGET_ACCOUNTOPERATION_H
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "operation.h"
|
||||
|
||||
namespace Budget::OptHandlers {
|
||||
class AccountOperation : public Operation {
|
||||
public:
|
||||
void commit() override;
|
||||
|
||||
explicit AccountOperation();
|
||||
|
||||
struct Flags : public Operation::Flags {
|
||||
bool del = false;
|
||||
bool forceDel = false;
|
||||
bool value = false;
|
||||
std::string description;
|
||||
};
|
||||
|
||||
Flags flags;
|
||||
private:
|
||||
};
|
||||
} // OptHandlers
|
||||
|
||||
#endif //BUDGET_ACCOUNTOPERATION_H
|
@ -2,6 +2,7 @@
|
||||
// Created by quentin on 1/8/23.
|
||||
//
|
||||
#include "mainOptHandler.h"
|
||||
#include "accountOperation.h"
|
||||
#include <iostream>
|
||||
#include <getopt.h>
|
||||
|
||||
@ -60,6 +61,8 @@ void MainOptHandler::accountOptHandler(std::string account) {
|
||||
{"description", no_argument, nullptr, 'D'},
|
||||
};
|
||||
|
||||
auto acctOperation = std::make_unique<AccountOperation>();
|
||||
|
||||
while (true) {
|
||||
int opt = getopt_long(argv.size(), argv.data(), "ha:c:e:p:dFvD", accountLongOpts, nullptr);
|
||||
if (opt == -1)
|
||||
@ -74,14 +77,20 @@ void MainOptHandler::accountOptHandler(std::string account) {
|
||||
case 'e':
|
||||
case 'p':
|
||||
optind--;
|
||||
operations.push(std::move(acctOperation));
|
||||
return;
|
||||
case 'd':
|
||||
acctOperation->flags.del = true;
|
||||
break;
|
||||
case 'F':
|
||||
acctOperation->flags.del = true;
|
||||
acctOperation->flags.forceDel = true;
|
||||
break;
|
||||
case 'v':
|
||||
acctOperation->flags.value = true;
|
||||
break;
|
||||
case 'D':
|
||||
acctOperation->flags.description = optarg;
|
||||
break;
|
||||
case '?':
|
||||
help();
|
||||
@ -90,6 +99,7 @@ void MainOptHandler::accountOptHandler(std::string account) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
operations.push(std::move(acctOperation));
|
||||
}
|
||||
|
||||
void MainOptHandler::createOptHandler(std::string account) {
|
||||
|
@ -7,6 +7,9 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <queue>
|
||||
#include <memory>
|
||||
#include "operation.h"
|
||||
|
||||
namespace Budget::OptHandlers{
|
||||
class MainOptHandler {
|
||||
@ -15,6 +18,8 @@ namespace Budget::OptHandlers{
|
||||
|
||||
void help();
|
||||
|
||||
std::queue<std::unique_ptr<Operation>> operations;
|
||||
|
||||
private:
|
||||
void accountOptHandler(std::string account);
|
||||
|
||||
|
5
src/optHandlers/operation.cpp
Normal file
5
src/optHandlers/operation.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by quentin on 1/17/23.
|
||||
//
|
||||
|
||||
#include "operation.h"
|
18
src/optHandlers/operation.h
Normal file
18
src/optHandlers/operation.h
Normal file
@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by quentin on 1/17/23.
|
||||
//
|
||||
|
||||
#ifndef BUDGET_OPERATION_H
|
||||
#define BUDGET_OPERATION_H
|
||||
|
||||
namespace Budget::OptHandlers {
|
||||
class Operation {
|
||||
public:
|
||||
virtual void commit() = 0;
|
||||
struct Flags {
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //BUDGET_OPERATION_H
|
Loading…
x
Reference in New Issue
Block a user