From 01101c84a06e5e6d9611ff4070cdf37c823b62d2 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Mon, 10 Feb 2025 17:15:32 -0500 Subject: [PATCH] cpplint: lint things a bit https://raw.githubusercontent.com/cpplint/cpplint/HEAD/cpplint.py Signed-off-by: Vincent Batts --- account.cpp | 2 ++ account.h | 34 ++++++++++++--------------- common.h | 7 +++--- main.cpp | 14 +++++------ worker.h | 68 ++++++++++++++++++++++++++++------------------------- 5 files changed, 64 insertions(+), 61 deletions(-) diff --git a/account.cpp b/account.cpp index 7e1b59b..c8fad87 100644 --- a/account.cpp +++ b/account.cpp @@ -1,3 +1,5 @@ +// Copyright 2025 Vincent Batts + #include #include "account.h" diff --git a/account.h b/account.h index a0d399b..bc0ddaf 100644 --- a/account.h +++ b/account.h @@ -1,41 +1,37 @@ +// Copyright 2025 Vincent Batts -#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: diff --git a/common.h b/common.h index e046400..770ee7f 100644 --- a/common.h +++ b/common.h @@ -1,6 +1,7 @@ +// Copyright 2025 Vincent Batts -#ifndef COMMON_H_INCLUDED_ -#define COMMON_H_INCLUDED_ +#ifndef COMMON_H_ +#define COMMON_H_ #include @@ -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: diff --git a/main.cpp b/main.cpp index d6874a8..179d7c9 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,4 @@ +// Copyright 2025 Vincent Batts /* * ===================================================================================== * @@ -19,15 +20,15 @@ #include #include -#include "common.h" -#include "account.h" -#include "worker.h" +#include "./common.h" +#include "./account.h" +#include "./worker.h" -Account* do_account() { +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; } diff --git a/worker.h b/worker.h index 4141846..13557b2 100644 --- a/worker.h +++ b/worker.h @@ -1,9 +1,11 @@ +// Copyright 2025 Vincent Batts + // 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 #include @@ -11,40 +13,42 @@ #include namespace Dang { - class Worker { - public: - Worker() { - this->ready = false; - //init(); - }; - - void run() { - std::unique_lock 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() { - std::thread daemon([this] {this->run();}); +class Worker { + public: + Worker() { + this->ready = false; + } - std::this_thread::sleep_for(std::chrono::seconds(5)); - { - std::lock_guard lock(this->mtx); - this->ready = true; - } - this->cv.notify_one(); + void run() { + std::unique_lock 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; + } - daemon.join(); - return 0; - }; + int work() { + std::thread daemon([this] {this->run();}); - private: - std::mutex mtx; - std::condition_variable cv; - bool ready; - }; -} + std::this_thread::sleep_for(std::chrono::seconds(5)); + { + std::lock_guard lock(this->mtx); + 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: