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;
{
try
{
- app_ = starter_->create_app(argc, argv);
+ _app = _starter->create_app(argc, argv);
}
catch(const usage_error &e)
{
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;
}
}
}
- delete app_;
- app_ = 0;
+ delete _app;
+ _app = 0;
return 124;
}
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;
if(exe.empty())
exe = FS::realpath(argv0);
- argv0_ = exe.c_str();
- data_ = data;
+ _argv0 = exe.c_str();
+ _data = data;
}
int Application::main()
void Application::catch_signal(int s)
{
- signal(s, &sighandler_);
+ signal(s, &_sighandler);
}
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
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());
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
private:
/** Static wrapper function to call a member function of the Application
instance. */
- static void sighandler_(int);
+ static void _sighandler(int);
};
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 T>
-typename RegisteredApplication<T>::Starter RegisteredApplication<T>::starter_;
+typename RegisteredApplication<T>::Starter RegisteredApplication<T>::_starter;
} // 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(); }
};
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<int>::min())
+ m_code(numeric_limits<int>::min())
{ }
} // 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);
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)
Thread *thread = reinterpret_cast<Thread *>(arg);
thread->platform_setname();
thread->main();
- thread->state_ = FINISHED;
+ thread->_state = FINISHED;
return 0;
}
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. */
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
}
virtual const std::type_info &type_id() const { return typeid(T); }
virtual StoreBase *clone() const { return new Store<T>(data); }
virtual bool type_equals(const StoreBase &s) const { return dynamic_cast<const Store<T> *>(&s); }
- virtual bool value_equals(const StoreBase &s) const { return value_equals_<T>(s); }
+ virtual bool value_equals(const StoreBase &s) const { return _value_equals<T>(s); }
template<typename U>
- typename std::enable_if<IsEqualityComparable<U>::value, bool>::type value_equals_(const StoreBase &s) const
+ typename std::enable_if<IsEqualityComparable<U>::value, bool>::type _value_equals(const StoreBase &s) const
{ const Store<T> *t = dynamic_cast<const Store<T> *>(&s); return (t && t->data==data); }
template<typename U>
- typename std::enable_if<!IsEqualityComparable<U>::value, bool>::type value_equals_(const StoreBase &) const
+ typename std::enable_if<!IsEqualityComparable<U>::value, bool>::type _value_equals(const StoreBase &) const
{ return false; }
};
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()
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
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;
};
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)
sigc::signal<void, PollEvent> signal_events_changed;
private:
- PollEvent events = P_NONE;
+ PollEvent _events = P_NONE;
protected:
EventObject();
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;
#else
runtime_error(w),
#endif
- code_(c)
+ m_code(c)
{ }
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; }
};
/**
}
template<typename T>
-inline int cmp_(T a, T b)
+inline int _cmp(T a, T b)
{
if(a<b)
return -1;
int DateTime::cmp(const DateTime &dt) const
{
- if(int c = cmp_(year, dt.year))
+ if(int c = _cmp(year, dt.year))
return c;
- if(int c = cmp_(month, dt.month))
+ if(int c = _cmp(month, dt.month))
return c;
- if(int c = cmp_(mday, dt.mday))
+ if(int c = _cmp(mday, dt.mday))
return c;
- if(int c = cmp_(hour, dt.hour))
+ if(int c = _cmp(hour, dt.hour))
return c;
- if(int c = cmp_(minute, dt.minute))
+ if(int c = _cmp(minute, dt.minute))
return c;
- if(int c = cmp_(second, dt.second))
+ if(int c = _cmp(second, dt.second))
return c;
- if(int c = cmp_(usec, dt.usec))
+ if(int c = _cmp(usec, dt.usec))
return c;
return 0;
}