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:
Vincent Batts 2025-02-10 17:15:32 -05:00
parent 78660fb70e
commit 01101c84a0
Signed by: vbatts
GPG key ID: E30EFAA812C6E5ED
5 changed files with 64 additions and 61 deletions

View file

@ -1,3 +1,5 @@
// Copyright 2025 Vincent Batts <vbatts@hashbangbash.com>
#include <iostream> #include <iostream>
#include "account.h" #include "account.h"

View file

@ -1,41 +1,37 @@
// Copyright 2025 Vincent Batts <vbatts@hashbangbash.com>
#ifndef ACCOUNT_H_INCLUDED_ #ifndef ACCOUNT_H_
#define ACCOUNT_H_INCLUDED_ #define ACCOUNT_H_
class Account class Account {
{
public: public:
/* ==================== LIFECYCLE */
explicit Account(double initial_balance);
~Account(); // destructor
/* ==================== LIFECYCLE ======================================= */ /* ==================== ACCESSORS */
//Account (); /* constructor */
//Account ( const Account &other ); /* copy constructor */
Account ( double initial_balance );
~Account (); /* destructor */
/* ==================== ACCESSORS ======================================= */
// current balance of the Account // current balance of the Account
double getBalance() const; double getBalance() const;
/* ==================== MUTATORS ======================================= */ /* ==================== MUTATORS */
void deposit(double amount); void deposit(double amount);
void withdraw(double amount); void withdraw(double amount);
/* ==================== OPERATORS ======================================= */ /* ==================== OPERATORS */
Account& operator = ( const Account &other ); /* assignment operator */ Account& operator = (const Account &other); // assignment operator
protected: protected:
/* ==================== DATA MEMBERS ======================================= */ /* ==================== DATA MEMBERS */
private: private:
/* ==================== DATA MEMBERS ======================================= */ /* ==================== DATA MEMBERS */
double balance; double balance;
};
}; /* ----- end of class Account ----- */ #endif // ACCOUNT_H_
#endif // ACCOUNT_H_INCLUDED_
// vim:set sts=2 sw=2 et: // vim:set sts=2 sw=2 et:

View file

@ -1,6 +1,7 @@
// Copyright 2025 Vincent Batts <vbatts@hashbangbash.com>
#ifndef COMMON_H_INCLUDED_ #ifndef COMMON_H_
#define COMMON_H_INCLUDED_ #define COMMON_H_
#include <iostream> #include <iostream>
@ -11,6 +12,6 @@
#define log_err(hurr) \ #define log_err(hurr) \
std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] " << hurr << std::endl; std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] " << hurr << std::endl;
#endif // COMMON_H_INCLUDED_ #endif // COMMON_H_
// vim:set sts=2 sw=2 et: // vim:set sts=2 sw=2 et:

View file

@ -1,3 +1,4 @@
// Copyright 2025 Vincent Batts <vbatts@hashbangbash.com>
/* /*
* ===================================================================================== * =====================================================================================
* *
@ -19,15 +20,15 @@
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include "common.h" #include "./common.h"
#include "account.h" #include "./account.h"
#include "worker.h" #include "./worker.h"
Account* do_account() { Account* do_account() {
Account* account = new Account(0.0); Account* account = new Account(0.0);
account->deposit(100.5); // Add some money account->deposit(100.5); // Add some money
account->deposit(50.25); // Add more money account->deposit(50.25); // Add more money
log_out("Current Balance: " << account->getBalance()); log_out("Current Balance: " << account->getBalance());
return account; return account;
} }
@ -39,7 +40,6 @@ void scoped_account() {
account->withdraw(100); account->withdraw(100);
log_out("Current Balance: " << account->getBalance()); log_out("Current Balance: " << account->getBalance());
log_err("dang"); log_err("dang");
delete account;
} }

View file

@ -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/thread
// https://en.cppreference.com/w/cpp/thread/mutex // https://en.cppreference.com/w/cpp/thread/mutex
// https://en.cppreference.com/w/cpp/thread/condition_variable // https://en.cppreference.com/w/cpp/thread/condition_variable
#ifndef WORKER_H_INCLUDED_ #ifndef WORKER_H_
#define WORKER_H_INCLUDED_ #define WORKER_H_
#include <iostream> #include <iostream>
#include <thread> #include <thread>
@ -11,40 +13,42 @@
#include <mutex> #include <mutex>
namespace Dang { 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;
};
int work() { class Worker {
std::thread daemon([this] {this->run();}); public:
Worker() {
this->ready = false;
}
std::this_thread::sleep_for(std::chrono::seconds(5)); void run() {
{ std::unique_lock<std::mutex> lock(this->mtx);
std::lock_guard<std::mutex> lock(this->mtx); // Wait until 'ready' is set to true
this->ready = true; this->cv.wait(lock, [this] { return this->ready; });
} std::cout << "Daemon process woke up!" << std::endl;
this->cv.notify_one(); }
daemon.join(); int work() {
return 0; std::thread daemon([this] {this->run();});
};
private: std::this_thread::sleep_for(std::chrono::seconds(5));
std::mutex mtx; {
std::condition_variable cv; std::lock_guard<std::mutex> lock(this->mtx);
bool ready; this->ready = true;
}; }
} this->cv.notify_one();
#endif // WORKER_H_INCLUDED_ daemon.join();
return 0;
}
private:
std::mutex mtx;
std::condition_variable cv;
bool ready;
};
} // namespace Dang
#endif // WORKER_H_
// vim:set sts=2 sw=2 et: // vim:set sts=2 sw=2 et: