From: Mikko Rasa Date: Sun, 31 Oct 2021 11:46:57 +0000 (+0200) Subject: Update naming of internal variables and functions X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5763dd6e8089c97699cbcbd221afb7fe1841bcdd;p=libs%2Fcore.git Update naming of internal variables and functions In most cases put just an underscore in front (instead of back as it was previously). When a member name conflicts with a noun function, use m_ prefix. --- diff --git a/source/core/application.cpp b/source/core/application.cpp index dda4440..1fbe154 100644 --- a/source/core/application.cpp +++ b/source/core/application.cpp @@ -15,26 +15,26 @@ using namespace std; namespace Msp { -Application *Application::app_ = 0; -Application::Starter *Application::starter_ = 0; -const char *Application::argv0_ = 0; -string Application::name_; -void *Application::data_ = 0; +Application *Application::_app = 0; +Application::Starter *Application::_starter = 0; +const char *Application::_argv0 = 0; +string Application::_name; +void *Application::_data = 0; Application::Application(const string &n) { - if(app_) + if(_app) throw logic_error("instance already exists"); if(!n.empty()) - name_ = n; + _name = n; else - name_ = FS::basename(argv0_); + _name = FS::basename(_argv0); } int Application::run(int argc, char **argv, void *data, void (*created_callback)(void *)) { - if(!starter_) + if(!_starter) { IO::cerr.write("Application::run called with no RegisteredApplication class!\n"); return 126; @@ -46,7 +46,7 @@ int Application::run(int argc, char **argv, void *data, void (*created_callback) { try { - app_ = starter_->create_app(argc, argv); + _app = _starter->create_app(argc, argv); } catch(const usage_error &e) { @@ -57,9 +57,9 @@ int Application::run(int argc, char **argv, void *data, void (*created_callback) if(created_callback) created_callback(data); - int result = app_->main(); - Application *a = app_; - app_ = 0; + int result = _app->main(); + Application *a = _app; + _app = 0; delete a; return result; } @@ -84,8 +84,8 @@ int Application::run(int argc, char **argv, void *data, void (*created_callback) } } - delete app_; - app_ = 0; + delete _app; + _app = 0; return 124; } @@ -93,7 +93,7 @@ int Application::run(int argc, char **argv, void *data, void (*created_callback) void Application::set_startup_info(const char *argv0, void *data) { - if(argv0_) + if(_argv0) throw logic_error("startup info already set"); static FS::Path exe; @@ -113,8 +113,8 @@ void Application::set_startup_info(const char *argv0, void *data) if(exe.empty()) exe = FS::realpath(argv0); - argv0_ = exe.c_str(); - data_ = data; + _argv0 = exe.c_str(); + _data = data; } int Application::main() @@ -128,7 +128,7 @@ int Application::main() void Application::catch_signal(int s) { - signal(s, &sighandler_); + signal(s, &_sighandler); } void Application::exit(int c) @@ -137,18 +137,18 @@ void Application::exit(int c) exit_code = c; } -void Application::sighandler_(int s) +void Application::_sighandler(int s) { - app_->sighandler(s); + _app->sighandler(s); } Application::Starter::Starter() { - if(starter_) + if(_starter) throw logic_error("Can't create more than one Starter instance"); - starter_ = this; + _starter = this; } } // namespace Msp diff --git a/source/core/application.h b/source/core/application.h index 019dee1..c3c693d 100644 --- a/source/core/application.h +++ b/source/core/application.h @@ -27,11 +27,11 @@ protected: int exit_code = 0; private: - static Starter *starter_; - static Application *app_; - static const char *argv0_; - static std::string name_; - static void *data_; + static Starter *_starter; + static Application *_app; + static const char *_argv0; + static std::string _name; + static void *_data; protected: Application(const std::string & = std::string()); @@ -53,9 +53,9 @@ public: Application::run(). */ static void set_startup_info(const char *, void *); - static void *get_data() { return data_; } - static const char *get_argv0() { return argv0_; } - static const std::string &get_name() { return name_; } + static void *get_data() { return _data; } + static const char *get_argv0() { return _argv0; } + static const std::string &get_name() { return _name; } protected: /** Default main loop. Calls tick() repeatedly until exit() is called. A @@ -76,7 +76,7 @@ protected: private: /** Static wrapper function to call a member function of the Application instance. */ - static void sighandler_(int); + static void _sighandler(int); }; @@ -94,16 +94,16 @@ private: Application *create_app(int argc, char **argv) { return new T(argc, argv); } }; - static Starter starter_; + static Starter _starter; protected: RegisteredApplication(const std::string &n = std::string()): Application(n) - { (void)starter_; } // Force the starter into existence + { (void)_starter; } // Force the starter into existence }; template -typename RegisteredApplication::Starter RegisteredApplication::starter_; +typename RegisteredApplication::Starter RegisteredApplication::_starter; } // namespace Msp diff --git a/source/core/getopt.h b/source/core/getopt.h index 5c21ccb..ed6cf86 100644 --- a/source/core/getopt.h +++ b/source/core/getopt.h @@ -13,13 +13,13 @@ namespace Msp { class usage_error: public std::runtime_error { private: - std::string help_; + std::string m_help; public: - usage_error(const std::string &w, const std::string &h = std::string()): std::runtime_error(w), help_(h) { } + usage_error(const std::string &w, const std::string &h = std::string()): std::runtime_error(w), m_help(h) { } virtual ~usage_error() throw() = default; - const char *help() const throw() { return help_.c_str(); } + const char *help() const throw() { return m_help.c_str(); } }; diff --git a/source/core/systemerror.cpp b/source/core/systemerror.cpp index 5424ef0..c6fd341 100644 --- a/source/core/systemerror.cpp +++ b/source/core/systemerror.cpp @@ -7,12 +7,12 @@ namespace Msp { system_error::system_error(const string &w, int c): runtime_error(w+": "+get_message(c)), - code_(c) + m_code(c) { } system_error::system_error(const string &w, const string &e): runtime_error(w+": "+e), - code_(numeric_limits::min()) + m_code(numeric_limits::min()) { } } // namespace Msp diff --git a/source/core/systemerror.h b/source/core/systemerror.h index d0a5634..1662cec 100644 --- a/source/core/systemerror.h +++ b/source/core/systemerror.h @@ -9,14 +9,14 @@ namespace Msp { class system_error: public std::runtime_error { private: - int code_; + int m_code; public: system_error(const std::string &, int = -1); system_error(const std::string &, const std::string &); virtual ~system_error() throw() = default; - int code() const throw() { return code_; } + int code() const throw() { return m_code; } private: static std::string get_message(int); diff --git a/source/core/thread.cpp b/source/core/thread.cpp index e03dcb8..841cc3f 100644 --- a/source/core/thread.cpp +++ b/source/core/thread.cpp @@ -7,42 +7,42 @@ using namespace std; namespace Msp { Thread::Thread(const string &name): - priv_(new Private), - name_(name) + _priv(new Private), + _name(name) { } Thread::~Thread() { kill(); join(); - delete priv_; + delete _priv; } void Thread::join() { - if(state_>=JOINED) + if(_state>=JOINED) return; platform_join(); - state_ = JOINED; + _state = JOINED; } void Thread::kill() { - if(state_!=RUNNING) + if(_state!=RUNNING) return; platform_kill(); - state_ = KILLED; + _state = KILLED; } void Thread::launch() { - if(state_>=RUNNING) + if(_state>=RUNNING) throw logic_error("already launched"); platform_launch(); - state_ = RUNNING; + _state = RUNNING; } ThreadReturn THREAD_CALL Thread::Private::main_wrapper(void *arg) @@ -50,7 +50,7 @@ ThreadReturn THREAD_CALL Thread::Private::main_wrapper(void *arg) Thread *thread = reinterpret_cast(arg); thread->platform_setname(); thread->main(); - thread->state_ = FINISHED; + thread->_state = FINISHED; return 0; } diff --git a/source/core/thread.h b/source/core/thread.h index c84fb66..ae9a0dd 100644 --- a/source/core/thread.h +++ b/source/core/thread.h @@ -27,19 +27,19 @@ private: JOINED }; - Private *priv_ = 0; - std::string name_; - State state_ = PENDING; + Private *_priv = 0; + std::string _name; + State _state = PENDING; protected: Thread(const std::string & = std::string()); public: virtual ~Thread(); - const std::string &get_name() const { return name_; } + const std::string &get_name() const { return _name; } /** Indicates whether the thread has finished running. */ - bool is_finished() { return state_>=FINISHED; } + bool is_finished() { return _state>=FINISHED; } /** Waits for the thread to exit. Calling this from the thread will cause a deadlock. */ diff --git a/source/core/unix/thread.cpp b/source/core/unix/thread.cpp index 119d55f..1ddcaae 100644 --- a/source/core/unix/thread.cpp +++ b/source/core/unix/thread.cpp @@ -7,24 +7,24 @@ namespace Msp { void Thread::platform_join() { - pthread_join(priv_->handle, 0); + pthread_join(_priv->handle, 0); } void Thread::platform_kill() { - pthread_kill(priv_->handle, SIGKILL); + pthread_kill(_priv->handle, SIGKILL); } void Thread::platform_launch() { - pthread_create(&priv_->handle, 0, &Private::main_wrapper, this); + pthread_create(&_priv->handle, 0, &Private::main_wrapper, this); } void Thread::platform_setname() { #if defined(__GLIBC__) && (__GLIBC__>2 || (__GLIBC__==2 && __GLIBC_MINOR__>=12)) - if(!name_.empty()) - pthread_setname_np(priv_->handle, name_.c_str()); + if(!_name.empty()) + pthread_setname_np(_priv->handle, _name.c_str()); #endif } diff --git a/source/core/variant.h b/source/core/variant.h index 1ad086e..2e9caaf 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -39,14 +39,14 @@ private: virtual const std::type_info &type_id() const { return typeid(T); } virtual StoreBase *clone() const { return new Store(data); } virtual bool type_equals(const StoreBase &s) const { return dynamic_cast *>(&s); } - virtual bool value_equals(const StoreBase &s) const { return value_equals_(s); } + virtual bool value_equals(const StoreBase &s) const { return _value_equals(s); } template - typename std::enable_if::value, bool>::type value_equals_(const StoreBase &s) const + typename std::enable_if::value, bool>::type _value_equals(const StoreBase &s) const { const Store *t = dynamic_cast *>(&s); return (t && t->data==data); } template - typename std::enable_if::value, bool>::type value_equals_(const StoreBase &) const + typename std::enable_if::value, bool>::type _value_equals(const StoreBase &) const { return false; } }; diff --git a/source/core/windows/thread.cpp b/source/core/windows/thread.cpp index ab02c4d..2483094 100644 --- a/source/core/windows/thread.cpp +++ b/source/core/windows/thread.cpp @@ -6,18 +6,18 @@ namespace Msp { void Thread::platform_join() { - WaitForSingleObject(priv_->handle, INFINITE); + WaitForSingleObject(_priv->handle, INFINITE); } void Thread::platform_kill() { - TerminateThread(priv_->handle, 0); + TerminateThread(_priv->handle, 0); } void Thread::platform_launch() { DWORD dummy; // Win9x needs the lpTthreadId parameter - priv_->handle = CreateThread(0, 0, &Private::main_wrapper, this, 0, &dummy); + _priv->handle = CreateThread(0, 0, &Private::main_wrapper, this, 0, &dummy); } void Thread::platform_setname() diff --git a/source/debug/errorreporter.cpp b/source/debug/errorreporter.cpp index d4d51bc..8f080a3 100644 --- a/source/debug/errorreporter.cpp +++ b/source/debug/errorreporter.cpp @@ -3,17 +3,17 @@ namespace Msp { namespace Debug { -ErrorReporter *ErrorReporter::current = 0; +ErrorReporter *ErrorReporter::_current = 0; ErrorReporter::ErrorReporter(): - prev(current) + _prev(_current) { - current = this; + _current = this; } ErrorReporter::~ErrorReporter() { - current = prev; + _current = _prev; } } // namespace Debug diff --git a/source/debug/errorreporter.h b/source/debug/errorreporter.h index 4a14674..dca8f52 100644 --- a/source/debug/errorreporter.h +++ b/source/debug/errorreporter.h @@ -10,16 +10,16 @@ namespace Debug { class ErrorReporter: private NonCopyable { private: - ErrorReporter *prev = 0; + ErrorReporter *_prev = 0; - static ErrorReporter *current; + static ErrorReporter *_current; protected: ErrorReporter(); public: virtual ~ErrorReporter(); - static const ErrorReporter *get_current() { return current; } + static const ErrorReporter *get_current() { return _current; } virtual bool report_uncaught_exception(const std::exception &) const = 0; }; diff --git a/source/io/eventobject.cpp b/source/io/eventobject.cpp index 714ed06..7d5ab5b 100644 --- a/source/io/eventobject.cpp +++ b/source/io/eventobject.cpp @@ -11,8 +11,8 @@ EventObject::~EventObject() void EventObject::set_events(PollEvent e) { - events = e; - signal_events_changed.emit(events); + _events = e; + signal_events_changed.emit(_events); } void EventObject::event(PollEvent ev) diff --git a/source/io/eventobject.h b/source/io/eventobject.h index 3feb74f..5a3b280 100644 --- a/source/io/eventobject.h +++ b/source/io/eventobject.h @@ -25,7 +25,7 @@ public: sigc::signal signal_events_changed; private: - PollEvent events = P_NONE; + PollEvent _events = P_NONE; protected: EventObject(); @@ -35,7 +35,7 @@ protected: public: /** Returns a mask of the currently interesting events. Used by EventDispatcher. */ - PollEvent get_events() const { return events; } + PollEvent get_events() const { return _events; } /** Returns a handle for polling. */ virtual const Handle &get_event_handle() = 0; diff --git a/source/io/zlibcompressed.cpp b/source/io/zlibcompressed.cpp index b3cb312..6c06cf3 100644 --- a/source/io/zlibcompressed.cpp +++ b/source/io/zlibcompressed.cpp @@ -14,7 +14,7 @@ zlib_error::zlib_error(const string &w, int c): #else runtime_error(w), #endif - code_(c) + m_code(c) { } diff --git a/source/io/zlibcompressed.h b/source/io/zlibcompressed.h index fb12d61..da7313b 100644 --- a/source/io/zlibcompressed.h +++ b/source/io/zlibcompressed.h @@ -12,13 +12,13 @@ namespace IO { class zlib_error: public std::runtime_error { private: - int code_; + int m_code; public: zlib_error(const std::string &, int); virtual ~zlib_error() throw() = default; - int code() const throw() { return code_; } + int code() const throw() { return m_code; } }; /** diff --git a/source/time/datetime.cpp b/source/time/datetime.cpp index f61e62e..e011f3b 100644 --- a/source/time/datetime.cpp +++ b/source/time/datetime.cpp @@ -29,7 +29,7 @@ inline unsigned char month_days(int y, unsigned char m) } template -inline int cmp_(T a, T b) +inline int _cmp(T a, T b) { if(a