From 122846f0881673770d88eff7d925ecf25c01b62e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 31 Oct 2021 13:08:16 +0200 Subject: [PATCH] Use default member initializers and constructor delegation --- source/core/android/mainthread.cpp | 3 +- source/core/android/mainthread.h | 6 ++-- source/core/application.cpp | 3 +- source/core/application.h | 4 +-- source/core/getopt.cpp | 6 +--- source/core/getopt.h | 18 +++++----- source/core/module.h | 2 +- source/core/mutex.h | 2 +- source/core/process.cpp | 19 ++-------- source/core/process.h | 17 +++++---- source/core/refptr.h | 12 +++---- source/core/semaphore.h | 2 +- source/core/thread.cpp | 3 +- source/core/thread.h | 4 +-- source/core/unix/semaphore.cpp | 5 ++- source/core/variant.h | 4 +-- source/debug/backtrace.h | 2 +- source/debug/errorreporter.h | 2 +- source/debug/profiler.cpp | 13 ------- source/debug/profiler.h | 16 ++++----- source/debug/profilingscope.h | 2 +- source/fs/filemonitor.cpp | 4 +-- source/fs/filemonitor.h | 8 ++--- source/fs/path.cpp | 10 ------ source/fs/path.h | 5 +-- source/fs/stat.cpp | 14 -------- source/fs/stat.h | 12 +++---- source/io/asset.h | 2 +- source/io/base.cpp | 5 +-- source/io/base.h | 6 ++-- source/io/buffered.cpp | 3 +- source/io/buffered.h | 10 +++--- source/io/eventobject.cpp | 3 +- source/io/eventobject.h | 2 +- source/io/eventreader.h | 2 +- source/io/handle.h | 2 +- source/io/memory.cpp | 21 ----------- source/io/memory.h | 15 ++++---- source/io/poll.cpp | 4 +-- source/io/poll.h | 10 +++--- source/io/slice.cpp | 4 +-- source/io/slice.h | 8 ++--- source/io/unix/eventreader.cpp | 3 +- source/io/windows/eventreader.cpp | 15 ++++---- source/io/zlibcompressed.cpp | 19 ---------- source/io/zlibcompressed.h | 16 ++++----- source/stringcodec/codec.h | 6 ++-- source/stringcodec/iso2022jp.cpp | 1 - source/stringcodec/iso2022jp.h | 8 ++--- source/stringcodec/jisx0208.h | 6 ++-- source/stringcodec/utf16.cpp | 3 +- source/stringcodec/utf16.h | 8 ++--- source/strings/fmt.cpp | 14 +------- source/strings/fmt.h | 28 +++++++-------- source/strings/lexicalcast.h | 4 +-- source/strings/regex.cpp | 1 - source/strings/regex.h | 2 +- source/strings/regmatch.h | 11 +++--- source/time/datetime.cpp | 58 ++++++++++-------------------- source/time/datetime.h | 18 ++++------ source/time/timedelta.h | 4 +-- source/time/timer.cpp | 3 +- source/time/timer.h | 4 +-- source/time/timestamp.h | 4 +-- 64 files changed, 179 insertions(+), 352 deletions(-) diff --git a/source/core/android/mainthread.cpp b/source/core/android/mainthread.cpp index 8ce484a..b816bf6 100644 --- a/source/core/android/mainthread.cpp +++ b/source/core/android/mainthread.cpp @@ -15,8 +15,7 @@ namespace Android { MainThread::MainThread(ANativeActivity *a): asset_manager(a->assetManager), - int_data_path(a->internalDataPath), - starting_up(true) + int_data_path(a->internalDataPath) { attach_to_activity(a); startup_mutex.lock(); diff --git a/source/core/android/mainthread.h b/source/core/android/mainthread.h index 609300f..99a641b 100644 --- a/source/core/android/mainthread.h +++ b/source/core/android/mainthread.h @@ -20,10 +20,10 @@ public: sigc::signal signal_input_queue_destroyed; private: - ANativeActivity *activity; - AAssetManager *asset_manager; + ANativeActivity *activity = 0; + AAssetManager *asset_manager = 0; FS::Path int_data_path; - bool starting_up; + bool starting_up = true; Mutex startup_mutex; public: diff --git a/source/core/application.cpp b/source/core/application.cpp index 2c6dc96..dda4440 100644 --- a/source/core/application.cpp +++ b/source/core/application.cpp @@ -21,8 +21,7 @@ const char *Application::argv0_ = 0; string Application::name_; void *Application::data_ = 0; -Application::Application(const string &n): - exit_code(0) +Application::Application(const string &n) { if(app_) throw logic_error("instance already exists"); diff --git a/source/core/application.h b/source/core/application.h index 93fccd8..40215ef 100644 --- a/source/core/application.h +++ b/source/core/application.h @@ -23,8 +23,8 @@ protected: virtual Application *create_app(int, char **) = 0; }; - bool done; - int exit_code; + bool done = false; + int exit_code = 0; private: static Starter *starter_; diff --git a/source/core/getopt.cpp b/source/core/getopt.cpp index 13e235f..cbc0afb 100644 --- a/source/core/getopt.cpp +++ b/source/core/getopt.cpp @@ -6,8 +6,7 @@ using namespace std; namespace Msp { -GetOpt::GetOpt(): - help(false) +GetOpt::GetOpt() { add_option("help", help, NO_ARG).set_help("Displays this help"); } @@ -318,9 +317,6 @@ GetOpt::OptionImpl::OptionImpl(char s, const string &l, const Store &t, ArgType shrt(s), lng(l), arg_type(a), - seen_count(0), - ext_seen_count(0), - metavar("ARG"), store(t.clone()) { } diff --git a/source/core/getopt.h b/source/core/getopt.h index 405864b..a1208f4 100644 --- a/source/core/getopt.h +++ b/source/core/getopt.h @@ -117,14 +117,14 @@ private: class OptionImpl: public Option { protected: - char shrt; + char shrt = 0; std::string lng; - ArgType arg_type; - unsigned seen_count; - unsigned *ext_seen_count; + ArgType arg_type = NO_ARG; + unsigned seen_count = 0; + unsigned *ext_seen_count = 0; std::string help; - std::string metavar; - Store *store; + std::string metavar = "ARG"; + Store *store = 0; public: OptionImpl(char, const std::string &, const Store &, ArgType); @@ -147,9 +147,9 @@ private: { private: std::string name; - ArgType type; + ArgType type = REQUIRED_ARG; std::string help; - Store *store; + Store *store = 0; public: ArgumentImpl(const std::string &, const Store &, ArgType); @@ -203,7 +203,7 @@ private: { data.push_back(lexical_cast(a)); } }; - bool help; + bool help = false; std::vector opts; std::vector args; std::vector args_raw; diff --git a/source/core/module.h b/source/core/module.h index 4a2f04c..339af08 100644 --- a/source/core/module.h +++ b/source/core/module.h @@ -11,7 +11,7 @@ class Module: private NonCopyable private: struct Private; - Private *priv; + Private *priv = 0; public: Module(const std::string &); diff --git a/source/core/mutex.h b/source/core/mutex.h index 3d3dc84..dc9a228 100644 --- a/source/core/mutex.h +++ b/source/core/mutex.h @@ -17,7 +17,7 @@ class Mutex: private NonCopyable private: struct Private; - Private *priv; + Private *priv = 0; public: Mutex(); diff --git a/source/core/process.cpp b/source/core/process.cpp index dfbea34..92475d4 100644 --- a/source/core/process.cpp +++ b/source/core/process.cpp @@ -10,26 +10,11 @@ Process *Process::_self = 0; Process::Process(const Private &p): priv(new Private(p)) -{ - init(); -} +{ } Process::Process(): priv(new Private) -{ - init(); -} - -void Process::init() -{ - redirect = false; - cin = 0; - cout = 0; - cerr = 0; - running = false; - finished = false; - exit_code = 0; -} +{ } Process &Process::self() { diff --git a/source/core/process.h b/source/core/process.h index 55b62cd..f21ecb3 100644 --- a/source/core/process.h +++ b/source/core/process.h @@ -30,20 +30,19 @@ public: private: struct Private; - Private *priv; + Private *priv = 0; FS::Path work_dir; - bool redirect; - IO::Base *cin; - IO::Base *cout; - IO::Base *cerr; - bool running; - bool finished; - unsigned exit_code; + bool redirect = false; + IO::Base *cin = 0; + IO::Base *cout = 0; + IO::Base *cerr = 0; + bool running = false; + bool finished = false; + unsigned exit_code = 0; static Process *_self; Process(const Private &); - void init(); public: Process(); ~Process(); diff --git a/source/core/refptr.h b/source/core/refptr.h index a2160a5..6285d0e 100644 --- a/source/core/refptr.h +++ b/source/core/refptr.h @@ -31,11 +31,11 @@ class RefPtr template friend class WeakPtr; private: - T *data; - RefCounts *counts; + T *data = 0; + RefCounts *counts = 0; public: - RefPtr(): data(0), counts(0) { } + RefPtr() { } RefPtr(T *d): data(d), counts(data ? new RefCounts : 0) { incref(); } private: RefPtr(T *d, RefCounts *c): data(d), counts(d ? c : 0) { incref(); } @@ -102,11 +102,11 @@ class WeakPtr template friend class WeakPtr; private: - T *data; - RefCounts *counts; + T *data = 0; + RefCounts *counts = 0; public: - WeakPtr(): data(0), counts(0) { } + WeakPtr() { } private: WeakPtr(T *d, RefCounts *c): data(d), counts(d ? c : 0) { incref(); } diff --git a/source/core/semaphore.h b/source/core/semaphore.h index 9ab25f2..4b22945 100644 --- a/source/core/semaphore.h +++ b/source/core/semaphore.h @@ -11,7 +11,7 @@ class Semaphore: private NonCopyable private: struct Private; - Private *priv; + Private *priv = 0; public: Semaphore(unsigned); diff --git a/source/core/thread.cpp b/source/core/thread.cpp index 721e8cf..e03dcb8 100644 --- a/source/core/thread.cpp +++ b/source/core/thread.cpp @@ -8,8 +8,7 @@ namespace Msp { Thread::Thread(const string &name): priv_(new Private), - name_(name), - state_(PENDING) + name_(name) { } Thread::~Thread() diff --git a/source/core/thread.h b/source/core/thread.h index 6a17912..c84fb66 100644 --- a/source/core/thread.h +++ b/source/core/thread.h @@ -27,9 +27,9 @@ private: JOINED }; - Private *priv_; + Private *priv_ = 0; std::string name_; - State state_; + State state_ = PENDING; protected: Thread(const std::string & = std::string()); diff --git a/source/core/unix/semaphore.cpp b/source/core/unix/semaphore.cpp index 8149258..6a4bacf 100644 --- a/source/core/unix/semaphore.cpp +++ b/source/core/unix/semaphore.cpp @@ -14,8 +14,8 @@ struct Semaphore::Private { Mutex mutex; pthread_cond_t cond; - unsigned limit; - unsigned count; + unsigned limit = 1; + unsigned count = 0; }; @@ -24,7 +24,6 @@ Semaphore::Semaphore(unsigned limit): { pthread_cond_init(&priv->cond, 0); priv->limit = limit; - priv->count = 0; } Semaphore::~Semaphore() diff --git a/source/core/variant.h b/source/core/variant.h index 5109dbc..05a8139 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -50,10 +50,10 @@ private: { return false; } }; - StoreBase *store; + StoreBase *store = 0; public: - Variant(): store(0) { } + Variant() { } template Variant(const T &v): store(new Store::type>(v)) { } Variant(const Variant &v): store(v.store ? v.store->clone() : 0) { } diff --git a/source/debug/backtrace.h b/source/debug/backtrace.h index 3f32ade..67cf62f 100644 --- a/source/debug/backtrace.h +++ b/source/debug/backtrace.h @@ -13,7 +13,7 @@ class Backtrace public: struct StackFrame { - void *address; + void *address = 0; std::string file; std::string symbol; }; diff --git a/source/debug/errorreporter.h b/source/debug/errorreporter.h index 98806dd..4a14674 100644 --- a/source/debug/errorreporter.h +++ b/source/debug/errorreporter.h @@ -10,7 +10,7 @@ namespace Debug { class ErrorReporter: private NonCopyable { private: - ErrorReporter *prev; + ErrorReporter *prev = 0; static ErrorReporter *current; diff --git a/source/debug/profiler.cpp b/source/debug/profiler.cpp index c82558b..65cc71c 100644 --- a/source/debug/profiler.cpp +++ b/source/debug/profiler.cpp @@ -7,11 +7,6 @@ using namespace std; namespace Msp { namespace Debug { -Profiler::Profiler(): - period(0), - inner(0) -{ } - void Profiler::set_period(unsigned p) { if(p==period) @@ -96,13 +91,5 @@ const Profiler::ScopeInfo &Profiler::get_scope(const string &sn) const return get_item(scopes, sn); } - -Profiler::ScopeInfo::ScopeInfo(): - calls(0), - calls_per_sec(0), - hist_pos(0), - hist_full(false) -{ } - } // namespace Debug } // namespace Msp diff --git a/source/debug/profiler.h b/source/debug/profiler.h index 521ce95..5018c7f 100644 --- a/source/debug/profiler.h +++ b/source/debug/profiler.h @@ -37,27 +37,23 @@ public: struct ScopeInfo { Time::TimeStamp first_call; - unsigned calls; + unsigned calls = 0; Time::TimeDelta total_time; Time::TimeDelta self_time; Time::TimeDelta avg_time; - float calls_per_sec; + float calls_per_sec = 0; std::vector history; - unsigned hist_pos; - bool hist_full; + unsigned hist_pos = 0; + bool hist_full = false; std::map called_from; - - ScopeInfo(); }; private: - unsigned period; + unsigned period = 0; std::map scopes; - ProfilingScope *inner; + ProfilingScope *inner = 0; public: - Profiler(); - /** Sets the averaging period for timing data, measured in calls. Previous average timings are cleared. */ void set_period(unsigned p); diff --git a/source/debug/profilingscope.h b/source/debug/profilingscope.h index 4e4294e..50b84ff 100644 --- a/source/debug/profilingscope.h +++ b/source/debug/profilingscope.h @@ -18,7 +18,7 @@ class ProfilingScope: private NonCopyable private: Profiler &profiler; std::string name; - ProfilingScope *parent; + ProfilingScope *parent = 0; Time::TimeStamp entry_time; Time::TimeDelta time_spent; Time::TimeDelta child_time; diff --git a/source/fs/filemonitor.cpp b/source/fs/filemonitor.cpp index 5ff5b78..a1b713b 100644 --- a/source/fs/filemonitor.cpp +++ b/source/fs/filemonitor.cpp @@ -8,8 +8,7 @@ namespace Msp { namespace FS { FileMonitor::FileMonitor(): - priv(new Private(*this)), - event_disp(0) + priv(new Private(*this)) { } FileMonitor::~FileMonitor() @@ -30,7 +29,6 @@ void FileMonitor::add_file(const FS::Path &path) { MonitoredFile file; file.path = path; - file.modified = false; prepare_file(file); files.push_back(file); } diff --git a/source/fs/filemonitor.h b/source/fs/filemonitor.h index e96aff6..9e72ad2 100644 --- a/source/fs/filemonitor.h +++ b/source/fs/filemonitor.h @@ -17,16 +17,16 @@ private: struct MonitoredFile { FS::Path path; - bool modified; - int tag; + bool modified = false; + int tag = -1; }; public: sigc::signal signal_file_modified; private: - Private *priv; - IO::EventDispatcher *event_disp; + Private *priv = 0; + IO::EventDispatcher *event_disp = 0; std::vector files; public: diff --git a/source/fs/path.cpp b/source/fs/path.cpp index a5a5a10..adf376f 100644 --- a/source/fs/path.cpp +++ b/source/fs/path.cpp @@ -21,16 +21,6 @@ Path::Path() { } Path::Path(const string &p) -{ - init(p); -} - -Path::Path(const char *p) -{ - init(p); -} - -void Path::init(const string &p) { if(p.empty()) return; diff --git a/source/fs/path.h b/source/fs/path.h index e0b593c..9cc0dc2 100644 --- a/source/fs/path.h +++ b/source/fs/path.h @@ -72,11 +72,8 @@ private: public: Path(); Path(const std::string &); - Path(const char *); -private: - void init(const std::string &); + Path(const char *p): Path(std::string(p)) { } -public: /// Returns the path as a string. const std::string &str() const { return path; } diff --git a/source/fs/stat.cpp b/source/fs/stat.cpp index 2269ae1..ae9f803 100644 --- a/source/fs/stat.cpp +++ b/source/fs/stat.cpp @@ -7,20 +7,6 @@ using namespace std; namespace Msp { namespace FS { -Stat::Private::Private(): - owner_id(0), - group_id(0) -{ } - - -Stat::Stat(): - exists(false), - type(UNKNOWN), - size(0), - alloc_size(0), - priv(0) -{ } - Stat::Stat(const Stat &other): exists(other.exists), type(other.type), diff --git a/source/fs/stat.h b/source/fs/stat.h index e2400ed..00e3eb9 100644 --- a/source/fs/stat.h +++ b/source/fs/stat.h @@ -33,16 +33,16 @@ private: std::string group; }; - bool exists; - FileType type; - FileSize size; - FileSize alloc_size; + bool exists = false; + FileType type = UNKNOWN; + FileSize size = 0; + FileSize alloc_size = 0; Time::TimeStamp mtime; mutable OwnerInfo owner_info; - Private *priv; + Private *priv = 0; public: - Stat(); + Stat() { } Stat(const Stat &); Stat &operator=(const Stat &); ~Stat(); diff --git a/source/io/asset.h b/source/io/asset.h index c5b98cb..e83355e 100644 --- a/source/io/asset.h +++ b/source/io/asset.h @@ -16,7 +16,7 @@ class Asset: public Seekable private: struct Private; - Private *priv; + Private *priv = 0; public: Asset(const std::string &); diff --git a/source/io/base.cpp b/source/io/base.cpp index 9c2b40a..b8c13d2 100644 --- a/source/io/base.cpp +++ b/source/io/base.cpp @@ -6,10 +6,7 @@ using namespace std; namespace Msp { namespace IO { -Base::Base(): - mode(M_READ), - eof_flag(false), - mutex(0) +Base::Base() { } Base::~Base() diff --git a/source/io/base.h b/source/io/base.h index 7bd5bd9..1a1485e 100644 --- a/source/io/base.h +++ b/source/io/base.h @@ -42,9 +42,9 @@ public: sigc::signal signal_deleted; protected: - Mode mode; - bool eof_flag; - Mutex *mutex; + Mode mode = M_READ; + bool eof_flag = false; + Mutex *mutex = 0; Base(); public: diff --git a/source/io/buffered.cpp b/source/io/buffered.cpp index 77a5f45..638e4ec 100644 --- a/source/io/buffered.cpp +++ b/source/io/buffered.cpp @@ -13,8 +13,7 @@ Buffered::Buffered(Base &b, unsigned s): buf_size(s), buf(new char[buf_size]), begin(buf), - end(buf), - cur_op(M_NONE) + end(buf) { mode = below.get_mode(); below.signal_flush_required.connect(sigc::mem_fun(this, &Buffered::flush)); diff --git a/source/io/buffered.h b/source/io/buffered.h index eeae3e4..39c8159 100644 --- a/source/io/buffered.h +++ b/source/io/buffered.h @@ -11,11 +11,11 @@ class Buffered: public Base, public sigc::trackable { private: Base &below; - std::size_t buf_size; - char *buf; - char *begin; - char *end; - Mode cur_op; + std::size_t buf_size = 0; + char *buf = 0; + char *begin = 0; + char *end = 0; + Mode cur_op = M_NONE; public: Buffered(Base &, unsigned = 8192); diff --git a/source/io/eventobject.cpp b/source/io/eventobject.cpp index 462e8bb..714ed06 100644 --- a/source/io/eventobject.cpp +++ b/source/io/eventobject.cpp @@ -3,8 +3,7 @@ namespace Msp { namespace IO { -EventObject::EventObject(): - events(P_NONE) +EventObject::EventObject() { } EventObject::~EventObject() diff --git a/source/io/eventobject.h b/source/io/eventobject.h index 88a71c7..3feb74f 100644 --- a/source/io/eventobject.h +++ b/source/io/eventobject.h @@ -25,7 +25,7 @@ public: sigc::signal signal_events_changed; private: - PollEvent events; + PollEvent events = P_NONE; protected: EventObject(); diff --git a/source/io/eventreader.h b/source/io/eventreader.h index 3c01f09..51785b0 100644 --- a/source/io/eventreader.h +++ b/source/io/eventreader.h @@ -25,7 +25,7 @@ private: struct Private; Handle &handle; - Private *priv; + Private *priv = 0; public: EventReader(Handle &, unsigned); diff --git a/source/io/handle.h b/source/io/handle.h index be2097e..3e06c71 100644 --- a/source/io/handle.h +++ b/source/io/handle.h @@ -12,7 +12,7 @@ public: struct Private; private: - Private *priv; + Private *priv = 0; public: Handle(); diff --git a/source/io/memory.cpp b/source/io/memory.cpp index 616150f..0b2d8f4 100644 --- a/source/io/memory.cpp +++ b/source/io/memory.cpp @@ -8,28 +8,7 @@ using namespace std; namespace Msp { namespace IO { -Memory::Memory(char *d, size_t s, Mode m) -{ - init(d, d+s, m); -} - Memory::Memory(char *b, char *e, Mode m) -{ - init(b, e, m); -} - -Memory::Memory(const char *cd, size_t s) -{ - char *d = const_cast(cd); - init(d, d+s, M_READ); -} - -Memory::Memory(const char *b, const char *e) -{ - init(const_cast(b), const_cast(e), M_READ); -} - -void Memory::init(char *b, char *e, Mode m) { begin = b; end = e; diff --git a/source/io/memory.h b/source/io/memory.h index 5b9961c..0486567 100644 --- a/source/io/memory.h +++ b/source/io/memory.h @@ -9,19 +9,16 @@ namespace IO { class Memory: public Seekable { private: - char *begin; - char *end; - char *pos; + char *begin = 0; + char *end = 0; + char *pos = 0; public: - Memory(char *, std::size_t, Mode = M_RDWR); + Memory(char *d, std::size_t s, Mode m = M_RDWR): Memory(d, d+s, m) { } Memory(char *, char *, Mode = M_RDWR); - Memory(const char *, std::size_t); - Memory(const char *, const char *); -private: - void init(char *, char *, Mode); + Memory(const char *d, std::size_t s): Memory(const_cast(d), const_cast(d+s), M_READ) { } + Memory(const char *b, const char *e): Memory(const_cast(b), const_cast(e), M_READ) { } -public: virtual void set_block(bool); virtual void set_inherit(bool); diff --git a/source/io/poll.cpp b/source/io/poll.cpp index 4ca2f3d..4f9b24f 100644 --- a/source/io/poll.cpp +++ b/source/io/poll.cpp @@ -10,9 +10,7 @@ namespace Msp { namespace IO { Poller::Poller(): - priv(new Private), - events_changed(false), - objs_changed(false) + priv(new Private) { } Poller::~Poller() diff --git a/source/io/poll.h b/source/io/poll.h index 0fb1ebc..ca0b0b7 100644 --- a/source/io/poll.h +++ b/source/io/poll.h @@ -36,8 +36,8 @@ class Poller: private NonCopyable public: struct PolledObject { - EventObject *object; - PollEvent events; + EventObject *object = 0; + PollEvent events = P_NONE; PolledObject(EventObject *o, PollEvent e): object(o), events(e) { } }; @@ -46,9 +46,9 @@ private: struct Private; std::vector objects; - Private *priv; - bool events_changed; - bool objs_changed; + Private *priv = 0; + bool events_changed = false; + bool objs_changed = false; std::vector poll_result; public: diff --git a/source/io/slice.cpp b/source/io/slice.cpp index 4007a5e..535deae 100644 --- a/source/io/slice.cpp +++ b/source/io/slice.cpp @@ -9,9 +9,7 @@ namespace IO { Slice::Slice(Seekable &b, SeekOffset s, SeekOffset l): below(b), start_offset(s), - length(l), - position(0), - sync_position(true) + length(l) { if(s<0 || l<0) throw invalid_argument("Slice"); diff --git a/source/io/slice.h b/source/io/slice.h index 8ca4327..cec1fcf 100644 --- a/source/io/slice.h +++ b/source/io/slice.h @@ -20,10 +20,10 @@ class Slice: public Seekable, public sigc::trackable { private: Seekable &below; - SeekOffset start_offset; - SeekOffset length; - SeekOffset position; - bool sync_position; + SeekOffset start_offset = 0; + SeekOffset length = 0; + SeekOffset position = 0; + bool sync_position = true; public: Slice(Seekable &, SeekOffset, SeekOffset); diff --git a/source/io/unix/eventreader.cpp b/source/io/unix/eventreader.cpp index fcbc892..afb1463 100644 --- a/source/io/unix/eventreader.cpp +++ b/source/io/unix/eventreader.cpp @@ -4,8 +4,7 @@ namespace Msp { namespace IO { EventReader::EventReader(Handle &h, unsigned): - handle(h), - priv(0) + handle(h) { } EventReader::~EventReader() diff --git a/source/io/windows/eventreader.cpp b/source/io/windows/eventreader.cpp index 82d9e8c..7406524 100644 --- a/source/io/windows/eventreader.cpp +++ b/source/io/windows/eventreader.cpp @@ -13,12 +13,12 @@ struct EventReader::Private { OVERLAPPED overlapped; Handle event; - unsigned buf_size; - char *buffer; - unsigned buf_avail; - char *buf_next; - bool pending; - bool eof; + unsigned buf_size = 0; + char *buffer = 0; + unsigned buf_avail = 0; + char *buf_next = 0; + bool pending = false; + bool eof = false; }; @@ -31,10 +31,7 @@ EventReader::EventReader(Handle &h, unsigned size): priv->overlapped.hEvent = *priv->event; priv->buf_size = size; priv->buffer = new char[priv->buf_size]; - priv->buf_avail = 0; priv->buf_next = priv->buffer; - priv->pending = false; - priv->eof = false; } EventReader::~EventReader() diff --git a/source/io/zlibcompressed.cpp b/source/io/zlibcompressed.cpp index 2220bcc..b3cb312 100644 --- a/source/io/zlibcompressed.cpp +++ b/source/io/zlibcompressed.cpp @@ -37,16 +37,6 @@ ZlibCompressed::Private::Private() } -ZlibCompressed::ZlibCompressed(Base &b, unsigned level): - below(b) -{ - mode = below.get_mode()&M_RDWR; - if(mode!=M_READ && mode!=M_WRITE) - throw invalid_access(mode); - - init(level); -} - ZlibCompressed::ZlibCompressed(Base &b, Mode m, unsigned level): below(b) { @@ -54,16 +44,7 @@ ZlibCompressed::ZlibCompressed(Base &b, Mode m, unsigned level): if(mode!=M_READ && mode!=M_WRITE) throw invalid_access(m); - init(level); -} - -void ZlibCompressed::init(unsigned level) -{ #ifdef WITH_ZLIB - buffer_size = 1024; - in_buffer = 0; - out_buffer = 0; - stream_end = false; priv = new Private; if(mode==M_WRITE) diff --git a/source/io/zlibcompressed.h b/source/io/zlibcompressed.h index e4ae6e0..f31bb23 100644 --- a/source/io/zlibcompressed.h +++ b/source/io/zlibcompressed.h @@ -34,26 +34,22 @@ private: struct Private; Base &below; - std::size_t buffer_size; - unsigned char *in_buffer; - unsigned char *out_buffer; - bool stream_end; - Private *priv; + std::size_t buffer_size = 1024; + unsigned char *in_buffer = 0; + unsigned char *out_buffer = 0; + bool stream_end = false; + Private *priv = 0; public: /** Creates a zlib de/compression object. The underlying object must be open for reading or writing, not both. The level parameter determines compression quality, ranging from 1 (fastest) to 9 (best compression). */ - ZlibCompressed(Base &, unsigned level = 9); + ZlibCompressed(Base &b, unsigned level = 9): ZlibCompressed(b, b.get_mode()&M_RDWR, level) { } /** Creates a zlib de/compression object. Mode must be either read or write, and compatible with the underlying object. */ ZlibCompressed(Base &, Mode, unsigned level = 9); -private: - void init(unsigned); - -public: virtual ~ZlibCompressed(); virtual void set_block(bool); diff --git a/source/stringcodec/codec.h b/source/stringcodec/codec.h index 1b89347..efa1657 100644 --- a/source/stringcodec/codec.h +++ b/source/stringcodec/codec.h @@ -39,7 +39,7 @@ public: class Encoder { protected: - ErrorMode err_mode; + ErrorMode err_mode = THROW_ON_ERROR; Encoder(ErrorMode em): err_mode(em==DEFAULT ? THROW_ON_ERROR : em) { } public: @@ -90,7 +90,7 @@ public: class Decoder { protected: - ErrorMode err_mode; + ErrorMode err_mode = THROW_ON_ERROR; Decoder(ErrorMode em): err_mode(em==DEFAULT ? THROW_ON_ERROR : em) { } public: @@ -162,7 +162,7 @@ template class StandardCodec: public Codec { private: - ErrorMode err_mode; + ErrorMode err_mode = THROW_ON_ERROR; protected: StandardCodec(ErrorMode em): err_mode(em==DEFAULT ? THROW_ON_ERROR : em) { } diff --git a/source/stringcodec/iso2022jp.cpp b/source/stringcodec/iso2022jp.cpp index 296c1ef..3332922 100644 --- a/source/stringcodec/iso2022jp.cpp +++ b/source/stringcodec/iso2022jp.cpp @@ -80,7 +80,6 @@ void Iso2022Jp::Encoder::transliterate(unichar, string &buf) Iso2022Jp::Decoder::Decoder(ErrorMode em): Codec::Decoder(em), - mode(ASCII), dec(new Ascii::Decoder) { } diff --git a/source/stringcodec/iso2022jp.h b/source/stringcodec/iso2022jp.h index aa5c78b..dd85014 100644 --- a/source/stringcodec/iso2022jp.h +++ b/source/stringcodec/iso2022jp.h @@ -19,10 +19,10 @@ public: class Encoder: public Codec::Encoder { private: - Mode mode; + Mode mode = ASCII; public: - Encoder(ErrorMode em = DEFAULT): Codec::Encoder(em), mode(ASCII) { } + Encoder(ErrorMode em = DEFAULT): Codec::Encoder(em) { } virtual void encode_char(unichar, std::string &); virtual void sync(std::string &); @@ -35,8 +35,8 @@ public: class Decoder: public Codec::Decoder { private: - Mode mode; - Codec::Decoder *dec; + Mode mode = ASCII; + Codec::Decoder *dec = 0; public: Decoder(ErrorMode = DEFAULT); diff --git a/source/stringcodec/jisx0208.h b/source/stringcodec/jisx0208.h index 293d277..ee7b687 100644 --- a/source/stringcodec/jisx0208.h +++ b/source/stringcodec/jisx0208.h @@ -40,10 +40,8 @@ public: struct Kuten { - unsigned short ku; - unsigned short ten; - - Kuten(): ku(0), ten(0) { } + unsigned short ku = 0; + unsigned short ten = 0; operator bool() { return ku!=0 && ten!=0; } }; diff --git a/source/stringcodec/utf16.cpp b/source/stringcodec/utf16.cpp index 13d49ad..f8ae093 100644 --- a/source/stringcodec/utf16.cpp +++ b/source/stringcodec/utf16.cpp @@ -7,8 +7,7 @@ namespace StringCodec { Utf16::Encoder::Encoder(ErrorMode em, Endian en): Codec::Encoder(em), - endian(en==AUTO ? BIG : en), - emit_bom(true) + endian(en==AUTO ? BIG : en) { } void Utf16::Encoder::encode_char(unichar ch, string &buf) diff --git a/source/stringcodec/utf16.h b/source/stringcodec/utf16.h index 7fecf1e..1850258 100644 --- a/source/stringcodec/utf16.h +++ b/source/stringcodec/utf16.h @@ -24,8 +24,8 @@ public: class Encoder: public Codec::Encoder { private: - Endian endian; - bool emit_bom; + Endian endian = BIG; + bool emit_bom = true; public: Encoder(ErrorMode em = DEFAULT, Endian en = BIG); @@ -38,7 +38,7 @@ public: class Decoder: public Codec::Decoder { private: - Endian endian; + Endian endian = AUTO; public: Decoder(ErrorMode em = DEFAULT, Endian en = AUTO); @@ -49,7 +49,7 @@ public: }; private: - Endian endian; + Endian endian = AUTO; public: Utf16(ErrorMode em = DEFAULT, Endian en = AUTO): diff --git a/source/strings/fmt.cpp b/source/strings/fmt.cpp index 07484dd..60703d8 100644 --- a/source/strings/fmt.cpp +++ b/source/strings/fmt.cpp @@ -91,19 +91,7 @@ void Fmt::parse(const char *s) Fmt &Fmt::reset() { - wd = 0; - prec = 6; - spos = false; - fillc = ' '; - base = DEC; - sbase = false; - fmode = AUTOFLT; - spoint = false; - align = RIGHT; - ucase = false; - type = STR; - - return *this; + return *this = Fmt(); } void Fmt::apply(ostream &out) const diff --git a/source/strings/fmt.h b/source/strings/fmt.h index ee84911..98e7e64 100644 --- a/source/strings/fmt.h +++ b/source/strings/fmt.h @@ -68,22 +68,22 @@ public: }; private: - unsigned wd; - unsigned prec; - bool spos; - wchar_t fillc; - Base base; - bool sbase; - FloatMode fmode; - bool spoint; - Align align; - bool ucase; - Type type; + unsigned wd = 0; + unsigned prec = 6; + bool spos = false; + wchar_t fillc = ' '; + Base base = DEC; + bool sbase = false; + FloatMode fmode = AUTOFLT; + bool spoint = false; + Align align = RIGHT; + bool ucase = false; + Type type = STR; public: - Fmt() { reset(); } - Fmt(const char *f) { reset(); parse(f); } - Fmt(const std::string &f) { reset(); parse(f.c_str()); } + Fmt() = default; + Fmt(const char *f) { parse(f); } + Fmt(const std::string &f) { parse(f.c_str()); } private: void parse(const char *); diff --git a/source/strings/lexicalcast.h b/source/strings/lexicalcast.h index 4f54a85..5d58080 100644 --- a/source/strings/lexicalcast.h +++ b/source/strings/lexicalcast.h @@ -38,11 +38,11 @@ class LexicalConverter { private: Fmt fmt; - bool filled; + bool filled = false; std::string buf; public: - LexicalConverter(const Fmt &f): fmt(f), filled(false) { } + LexicalConverter(const Fmt &f): fmt(f) { } LexicalConverter(const std::string &s, const Fmt &f): fmt(f), filled(true), buf(s) { } const Fmt &get_fmt() const { return fmt; } diff --git a/source/strings/regex.cpp b/source/strings/regex.cpp index c624056..915d335 100644 --- a/source/strings/regex.cpp +++ b/source/strings/regex.cpp @@ -56,7 +56,6 @@ string bad_regex::make_where(const string &e, const string::const_iterator &i) Regex::Regex(const string &expr) { - n_groups = 0; auto iter = expr.begin(); code = compile(expr, iter, n_groups, false); ++n_groups; diff --git a/source/strings/regex.h b/source/strings/regex.h index 094a295..e830c5b 100644 --- a/source/strings/regex.h +++ b/source/strings/regex.h @@ -107,7 +107,7 @@ private: }; Code code; - unsigned n_groups; + unsigned n_groups = 0; public: /** Constructs a new Regex object from a string representation. */ diff --git a/source/strings/regmatch.h b/source/strings/regmatch.h index b79104b..0858e5a 100644 --- a/source/strings/regmatch.h +++ b/source/strings/regmatch.h @@ -26,13 +26,12 @@ public: { typedef std::string::size_type size_type; - bool match; //< Whether or not this group matched - size_type begin; //< First offset of the match - size_type end; //< One-past-last offset - size_type length; //< Length of the match (end-begin) - std::string str; //< The part of the string that matched + bool match = false; //< Whether or not this group matched + size_type begin; //< First offset of the match + size_type end; //< One-past-last offset + size_type length; //< Length of the match (end-begin) + std::string str; //< The part of the string that matched - Group(): match(false) { } operator bool() const { return match; } }; diff --git a/source/time/datetime.cpp b/source/time/datetime.cpp index e1abcf7..f61e62e 100644 --- a/source/time/datetime.cpp +++ b/source/time/datetime.cpp @@ -45,52 +45,32 @@ namespace Time { DateTime::DateTime(const TimeStamp &ts) { - init(ts); + add_raw(ts.raw()); } -DateTime::DateTime(const TimeStamp &ts, const TimeZone &tz) +DateTime::DateTime(const TimeStamp &ts, const TimeZone &tz): + DateTime(ts) { - init(ts); convert_timezone(tz); } -DateTime::DateTime(int y, unsigned char m, unsigned char d) -{ - init(y, m, d, 0, 0, 0, 0); -} - -DateTime::DateTime(int y, unsigned char m, unsigned char d, unsigned char h, unsigned char n, unsigned char s) +DateTime::DateTime(int y, unsigned char m, unsigned char d): + DateTime(y, m, d, 0, 0, 0, 0) +{ } + +DateTime::DateTime(int y, unsigned char m, unsigned char d, unsigned char h, unsigned char n, unsigned char s): + DateTime(y, m, d, h, n, s, 0) +{ } + +DateTime::DateTime(int y, unsigned char m, unsigned char d, unsigned char h, unsigned char n, unsigned char s, unsigned u): + year(y), + month(m), + mday(d), + hour(h), + minute(n), + second(s), + usec(u) { - init(y, m, d, h, n, s, 0); -} - -DateTime::DateTime(int y, unsigned char m, unsigned char d, unsigned char h, unsigned char n, unsigned char s, unsigned u) -{ - init(y, m, d, h, n, s, u); -} - -void DateTime::init(const TimeStamp &ts) -{ - year = 1970; - month = 1; - mday = 1; - hour = 0; - minute = 0; - second = 0; - usec = 0; - add_raw(ts.raw()); -} - -void DateTime::init(int y, unsigned char m, unsigned char d, unsigned char h, unsigned char n, unsigned char s, unsigned u) -{ - year = y; - month = m; - mday = d; - hour = h; - minute = n; - second = s; - usec = u; - if(usec>=1000000) throw out_of_range("DateTime::DateTime usec"); if(second>=60) diff --git a/source/time/datetime.h b/source/time/datetime.h index b7f578c..a5d91cf 100644 --- a/source/time/datetime.h +++ b/source/time/datetime.h @@ -23,13 +23,13 @@ TimeStamp is a better choice. class DateTime { private: - int year; - unsigned char month; - unsigned char mday; - unsigned char hour; - unsigned char minute; - unsigned char second; - unsigned usec; + int year = 1970; + unsigned char month = 1; + unsigned char mday = 1; + unsigned char hour = 0; + unsigned char minute = 0; + unsigned char second = 0; + unsigned usec = 0; TimeZone zone; public: @@ -38,11 +38,7 @@ public: DateTime(int, unsigned char, unsigned char); DateTime(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char); DateTime(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned); -private: - void init(const TimeStamp &); - void init(int, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned); -public: static DateTime parse_rfc3339(const std::string &); int get_year() const { return year; } diff --git a/source/time/timedelta.h b/source/time/timedelta.h index 2ce6eeb..3326835 100644 --- a/source/time/timedelta.h +++ b/source/time/timedelta.h @@ -15,11 +15,11 @@ Represents a quantity of time, such as five seconds. class TimeDelta { private: - RawTime usec; + RawTime usec = 0; public: /** Constructs a zero TimeDelta. */ - TimeDelta(): usec(0) { } + TimeDelta() { } /** Constructs a TimeDelta from a plain number. The purpose of this is to allow serialization together with the raw() function. */ diff --git a/source/time/timer.cpp b/source/time/timer.cpp index 9411fac..d35d127 100644 --- a/source/time/timer.cpp +++ b/source/time/timer.cpp @@ -9,8 +9,7 @@ namespace Msp { namespace Time { Timer::Timer(): - sem(1), - blocking(false) + sem(1) { } Timer::~Timer() diff --git a/source/time/timer.h b/source/time/timer.h index 8bd4d07..91acda9 100644 --- a/source/time/timer.h +++ b/source/time/timer.h @@ -41,7 +41,7 @@ public: private: struct SlotProxy { - Slot *slot; + Slot *slot = 0; SlotProxy(Slot *); bool operator<(const SlotProxy &) const; @@ -50,7 +50,7 @@ private: std::vector slots; Semaphore sem; Mutex mutex; - bool blocking; + bool blocking = false; public: Timer(); diff --git a/source/time/timestamp.h b/source/time/timestamp.h index 1317b26..d16bb06 100644 --- a/source/time/timestamp.h +++ b/source/time/timestamp.h @@ -16,12 +16,12 @@ For representing user-specified times, use the DateTime class. class TimeStamp { private: - RawTime usec; + RawTime usec = 0; public: /** Construct a TimeStamp that represents an arbitarily distant point in the past. It's guaranteed to be less than any valid timestamp. */ - TimeStamp(): usec(0) { } + TimeStamp() { } /** Constructs a TimeStamp from a plain number. The purpose of this is to allow serialization together with the raw() function. */ -- 2.43.0