Operations and AccountOperations boilerplate

This commit is contained in:
Quentin Snow 2023-01-17 11:58:31 -06:00
parent 94e63e8f76
commit 287f9f4751
7 changed files with 85 additions and 1 deletions

View File

@ -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)

View 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;

View 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

View File

@ -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) {

View File

@ -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);

View File

@ -0,0 +1,5 @@
//
// Created by quentin on 1/17/23.
//
#include "operation.h"

View 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