cpplint: lint things a bit
https://raw.githubusercontent.com/cpplint/cpplint/HEAD/cpplint.py Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
78660fb70e
commit
01101c84a0
5 changed files with 64 additions and 61 deletions
|
@ -1,3 +1,5 @@
|
|||
// Copyright 2025 Vincent Batts <vbatts@hashbangbash.com>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "account.h"
|
||||
|
|
34
account.h
34
account.h
|
@ -1,41 +1,37 @@
|
|||
// Copyright 2025 Vincent Batts <vbatts@hashbangbash.com>
|
||||
|
||||
#ifndef ACCOUNT_H_INCLUDED_
|
||||
#define ACCOUNT_H_INCLUDED_
|
||||
#ifndef ACCOUNT_H_
|
||||
#define ACCOUNT_H_
|
||||
|
||||
class Account
|
||||
{
|
||||
class Account {
|
||||
public:
|
||||
/* ==================== LIFECYCLE */
|
||||
explicit Account(double initial_balance);
|
||||
~Account(); // destructor
|
||||
|
||||
/* ==================== LIFECYCLE ======================================= */
|
||||
//Account (); /* constructor */
|
||||
//Account ( const Account &other ); /* copy constructor */
|
||||
Account ( double initial_balance );
|
||||
~Account (); /* destructor */
|
||||
|
||||
/* ==================== ACCESSORS ======================================= */
|
||||
/* ==================== ACCESSORS */
|
||||
|
||||
// current balance of the Account
|
||||
double getBalance() const;
|
||||
|
||||
/* ==================== MUTATORS ======================================= */
|
||||
/* ==================== MUTATORS */
|
||||
|
||||
void deposit(double amount);
|
||||
void withdraw(double amount);
|
||||
|
||||
/* ==================== OPERATORS ======================================= */
|
||||
/* ==================== OPERATORS */
|
||||
|
||||
Account& operator = ( const Account &other ); /* assignment operator */
|
||||
Account& operator = (const Account &other); // assignment operator
|
||||
|
||||
protected:
|
||||
/* ==================== DATA MEMBERS ======================================= */
|
||||
/* ==================== DATA MEMBERS */
|
||||
|
||||
private:
|
||||
/* ==================== DATA MEMBERS ======================================= */
|
||||
/* ==================== DATA MEMBERS */
|
||||
|
||||
double balance;
|
||||
};
|
||||
|
||||
}; /* ----- end of class Account ----- */
|
||||
|
||||
#endif // ACCOUNT_H_INCLUDED_
|
||||
#endif // ACCOUNT_H_
|
||||
|
||||
// vim:set sts=2 sw=2 et:
|
||||
|
|
7
common.h
7
common.h
|
@ -1,6 +1,7 @@
|
|||
// Copyright 2025 Vincent Batts <vbatts@hashbangbash.com>
|
||||
|
||||
#ifndef COMMON_H_INCLUDED_
|
||||
#define COMMON_H_INCLUDED_
|
||||
#ifndef COMMON_H_
|
||||
#define COMMON_H_
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
@ -11,6 +12,6 @@
|
|||
#define log_err(hurr) \
|
||||
std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] " << hurr << std::endl;
|
||||
|
||||
#endif // COMMON_H_INCLUDED_
|
||||
#endif // COMMON_H_
|
||||
|
||||
// vim:set sts=2 sw=2 et:
|
||||
|
|
12
main.cpp
12
main.cpp
|
@ -1,3 +1,4 @@
|
|||
// Copyright 2025 Vincent Batts <vbatts@hashbangbash.com>
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
|
@ -19,15 +20,15 @@
|
|||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "common.h"
|
||||
#include "account.h"
|
||||
#include "worker.h"
|
||||
#include "./common.h"
|
||||
#include "./account.h"
|
||||
#include "./worker.h"
|
||||
|
||||
Account* do_account() {
|
||||
Account* account = new Account(0.0);
|
||||
|
||||
account->deposit(100.5); // Add some money
|
||||
account->deposit(50.25); // Add more money
|
||||
account->deposit(100.5); // Add some money
|
||||
account->deposit(50.25); // Add more money
|
||||
log_out("Current Balance: " << account->getBalance());
|
||||
return account;
|
||||
}
|
||||
|
@ -39,7 +40,6 @@ void scoped_account() {
|
|||
account->withdraw(100);
|
||||
log_out("Current Balance: " << account->getBalance());
|
||||
log_err("dang");
|
||||
delete account;
|
||||
}
|
||||
|
||||
|
||||
|
|
66
worker.h
66
worker.h
|
@ -1,9 +1,11 @@
|
|||
// Copyright 2025 Vincent Batts <vbatts@hashbangbash.com>
|
||||
|
||||
// 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_
|
||||
#ifndef WORKER_H_
|
||||
#define WORKER_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
@ -11,40 +13,42 @@
|
|||
#include <mutex>
|
||||
|
||||
namespace Dang {
|
||||
class Worker {
|
||||
public:
|
||||
Worker() {
|
||||
this->ready = false;
|
||||
//init();
|
||||
};
|
||||
|
||||
void run() {
|
||||
std::unique_lock<std::mutex> lock(this->mtx);
|
||||
this->cv.wait(lock, [this] { return this->ready; }); // Wait until 'ready' is set to true
|
||||
std::cout << "Daemon process woke up!" << std::endl;
|
||||
};
|
||||
class Worker {
|
||||
public:
|
||||
Worker() {
|
||||
this->ready = false;
|
||||
}
|
||||
|
||||
int work() {
|
||||
std::thread daemon([this] {this->run();});
|
||||
void run() {
|
||||
std::unique_lock<std::mutex> lock(this->mtx);
|
||||
// Wait until 'ready' is set to true
|
||||
this->cv.wait(lock, [this] { return this->ready; });
|
||||
std::cout << "Daemon process woke up!" << std::endl;
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mtx);
|
||||
this->ready = true;
|
||||
}
|
||||
this->cv.notify_one();
|
||||
int work() {
|
||||
std::thread daemon([this] {this->run();});
|
||||
|
||||
daemon.join();
|
||||
return 0;
|
||||
};
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mtx);
|
||||
this->ready = true;
|
||||
}
|
||||
this->cv.notify_one();
|
||||
|
||||
private:
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
bool ready;
|
||||
};
|
||||
}
|
||||
daemon.join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // WORKER_H_INCLUDED_
|
||||
private:
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
bool ready;
|
||||
};
|
||||
|
||||
} // namespace Dang
|
||||
|
||||
#endif // WORKER_H_
|
||||
|
||||
// vim:set sts=2 sw=2 et:
|
||||
|
|
Loading…
Add table
Reference in a new issue