*: shaping into a project structure
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
768916ff0d
commit
e62400400d
6 changed files with 59 additions and 23 deletions
13
account.h
13
account.h
|
@ -1,12 +1,7 @@
|
|||
|
||||
#ifndef ACCOUNT_H
|
||||
#define ACCOUNT_H
|
||||
/*
|
||||
* =====================================================================================
|
||||
* Class: Account
|
||||
* Description:
|
||||
* =====================================================================================
|
||||
*/
|
||||
#ifndef ACCOUNT_H_INCLUDED_
|
||||
#define ACCOUNT_H_INCLUDED_
|
||||
|
||||
class Account
|
||||
{
|
||||
public:
|
||||
|
@ -41,6 +36,6 @@ class Account
|
|||
|
||||
}; /* ----- end of class Account ----- */
|
||||
|
||||
#endif
|
||||
#endif // ACCOUNT_H_INCLUDED_
|
||||
|
||||
// vim:set sts=2 sw=2 et:
|
||||
|
|
15
common.h
Normal file
15
common.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
#ifndef COMMON_H_INCLUDED_
|
||||
#define COMMON_H_INCLUDED_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define log_out(hurr) \
|
||||
std::cout << "[" << __FILE__ << ":" << __LINE__ << "] " << hurr << std::endl;
|
||||
#define log_err(hurr) \
|
||||
std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] " << hurr << std::endl;
|
||||
|
||||
|
||||
#endif // COMMON_H_INCLUDED_
|
||||
|
||||
// vim:set sts=2 sw=2 et:
|
28
main.cpp
28
main.cpp
|
@ -19,16 +19,38 @@
|
|||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "common.h"
|
||||
#include "account.h"
|
||||
#include "worker.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
Account* do_account() {
|
||||
Account account(0.0);
|
||||
|
||||
account.deposit(100.5); // Add some money
|
||||
account.deposit(50.25); // Add more money
|
||||
std::cout << "Current Balance: " << account.getBalance() << std::endl;
|
||||
log_out("HERE");
|
||||
return &account;
|
||||
}
|
||||
|
||||
void scoped_account() {
|
||||
log_out("HERE");
|
||||
auto account = do_account();
|
||||
log_out("HERE");
|
||||
log_err("dang");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int ret;
|
||||
|
||||
scoped_account();
|
||||
|
||||
Dang::Worker worker;
|
||||
ret = worker.work();
|
||||
if (ret != 0) {
|
||||
std::cout << "worker failed" << std::endl;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -8,9 +8,14 @@ a = run_command('date', check: true)
|
|||
read_exe = executable('read', 'read.c', link_language : 'c',)
|
||||
readpp_exe = executable('read++', 'read++.cpp')
|
||||
|
||||
worker_exe = executable('worker', 'worker.cpp')
|
||||
#worker_exe = executable('worker', 'worker.cpp')
|
||||
|
||||
account_sources = ['main.cpp', 'account.cpp', 'account.h']
|
||||
account_sources = [
|
||||
'main.cpp',
|
||||
'common.h',
|
||||
'account.cpp', 'account.h',
|
||||
'worker.h',
|
||||
]
|
||||
account_exe = executable('account', account_sources,
|
||||
cpp_args: ['-std=c++23'],
|
||||
)
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
// https://en.cppreference.com/w/cpp/thread/thread
|
||||
// https://en.cppreference.com/w/cpp/thread/mutex
|
||||
// https://en.cppreference.com/w/cpp/thread/condition_variable
|
||||
|
||||
#ifndef WORKER_H_INCLUDED_
|
||||
#define WORKER_H_INCLUDED_
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
// https://en.cppreference.com/w/cpp/thread/thread
|
||||
// https://en.cppreference.com/w/cpp/thread/mutex
|
||||
// https://en.cppreference.com/w/cpp/thread/condition_variable
|
||||
|
||||
namespace Dang {
|
||||
class Worker {
|
||||
public:
|
||||
|
@ -42,10 +45,6 @@ namespace Dang {
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
Dang::Worker worker;
|
||||
return worker.work();
|
||||
}
|
||||
#endif // WORKER_H_INCLUDED_
|
||||
|
||||
// vim:set sts=2 sw=2 et:
|
Loading…
Add table
Reference in a new issue