From 6c8446cddb37df732fc9e5fc21f98e31968ce634 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 1 Feb 2008 19:34:47 +0000 Subject: interface cleanup --- src/common/Makefile.am | 4 +-- src/common/common.cc | 20 -------------- src/common/common.h | 13 +++------ src/common/console.cc | 36 ------------------------- src/common/console.h | 60 ------------------------------------------ src/common/consoleinterface.cc | 36 +++++++++++++++++++++++++ src/common/consoleinterface.h | 59 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 100 insertions(+), 128 deletions(-) delete mode 100644 src/common/common.cc delete mode 100644 src/common/console.cc delete mode 100644 src/common/console.h create mode 100644 src/common/consoleinterface.cc create mode 100644 src/common/consoleinterface.h (limited to 'src/common') diff --git a/src/common/Makefile.am b/src/common/Makefile.am index dd5c5d1..a3f50a6 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -1,6 +1,6 @@ METASOURCES = AUTO -libcommon_la_SOURCES = common.cc console.cc +libcommon_la_SOURCES = consoleinterface.cc libcommon_la_LDFLAGS = -avoid-version -no-undefined noinst_LTLIBRARIES = libcommon.la -noinst_HEADERS = common.h console.h +noinst_HEADERS = common.h consoleinterface.h INCLUDES = -I$(top_srcdir)/src diff --git a/src/common/common.cc b/src/common/common.cc deleted file mode 100644 index cb968c0..0000000 --- a/src/common/common.cc +++ /dev/null @@ -1,20 +0,0 @@ -/* - common/common.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -#include "common/common.h" - -namespace common { - -void init() { - con_debug << "Initializing common..." << std::endl; -} - -void shutdown() { - con_debug << "Shutting down common..." << std::endl; -} - -} - diff --git a/src/common/common.h b/src/common/common.h index 1be6827..61aa47c 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -9,18 +9,11 @@ #include "config.h" -/// common functions and components that are used by the other subsytems -namespace common { +/// common functions and components that can be use by any subsytem +namespace common {} - /// initialize common components - void init(); +#include "common/consoleinterface.h" - /// shutdown common components - void shutdown(); - -} - -#include "common/console.h" #endif // __INCLUDED_COMMON_H__ diff --git a/src/common/console.cc b/src/common/console.cc deleted file mode 100644 index a7d0dd7..0000000 --- a/src/common/console.cc +++ /dev/null @@ -1,36 +0,0 @@ -/* - common/console.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -#include "common/console.h" - -#include - -#include - -namespace common { - -Console *Console::console_instance = 0; - -Console::Console() { - if (console_instance) { - std::cerr << "duplicate common::Console::console_instance" << std::endl; - exit(2); - } - console_instance = this; -} - -Console::~Console() -{ - console_instance = 0; -} - -Console *Console::instance() -{ - return console_instance; -} - -} // namespace common - diff --git a/src/common/console.h b/src/common/console.h deleted file mode 100644 index 0706f11..0000000 --- a/src/common/console.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - common/console.h - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2. -*/ - -#ifndef __INCLUDED_COMMON_CONSOLE_H__ -#define __INCLUDED_COMMON_CONSOLE_H__ - -// project headers -#include "common/common.h" - -// C++ headers -#include - -/// global define to send a message to the system console -#define con_print common::Console::instance()->messagestream() -/// global define to send a warning message to the system console -#define con_warn common::Console::instance()->warningstream() - -#ifdef HAVE_DEBUG_MESSAGES -/// global define to send a debug message to the system console -#define con_debug common::Console::instance()->debugstream() -#else -#define con_debug if (0) *(std::ostream*)(0) -#endif - -namespace common { - -/// interface for a console object that writes messages on the screen -class Console { -public: - /// default constructor - Console(); - - /// default destructor - virtual ~Console(); - - /// stream to send normal messages too - virtual std::ostream & messagestream() = 0; - - /// stream to send warning messages too - virtual std::ostream & warningstream() = 0; - - /// stream to send debug messages too - virtual std::ostream & debugstream() = 0; - - /// a pointer to the current console instance - static Console *instance(); - -private: - /// console singleton - static Console *console_instance; -} -; // class Console - -} // namespace common - -#endif // __INCLUDED_COMMON_CONSOLE_H__ - diff --git a/src/common/consoleinterface.cc b/src/common/consoleinterface.cc new file mode 100644 index 0000000..eb532c6 --- /dev/null +++ b/src/common/consoleinterface.cc @@ -0,0 +1,36 @@ +/* + common/consoleinterface.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "common/consoleinterface.h" + +#include + +#include + +namespace common { + +ConsoleInterface *ConsoleInterface::consoleinterface_instance = 0; + +ConsoleInterface::ConsoleInterface() { + if (consoleinterface_instance) { + std::cerr << "multiple singleton instances: common::ConsoleInterface" << std::endl; + exit(2); + } + consoleinterface_instance = this; +} + +ConsoleInterface::~ConsoleInterface() +{ + consoleinterface_instance = 0; +} + +ConsoleInterface *ConsoleInterface::instance() +{ + return consoleinterface_instance; +} + +} // namespace common + diff --git a/src/common/consoleinterface.h b/src/common/consoleinterface.h new file mode 100644 index 0000000..ec77e1d --- /dev/null +++ b/src/common/consoleinterface.h @@ -0,0 +1,59 @@ +/* + common/consoleinterface.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2. +*/ + +#ifndef __INCLUDED_COMMON_CONSOLEINTERFACE_H__ +#define __INCLUDED_COMMON_CONSOLEINTERFACE_H__ + +// project headers +#include "common/common.h" + +// C++ headers +#include + +/// global define to send a message to the system console +#define con_print common::ConsoleInterface::instance()->messagestream() +/// global define to send a warning message to the system console +#define con_warn common::ConsoleInterface::instance()->warningstream() + +#ifdef HAVE_DEBUG_MESSAGES +/// global define to send a debug message to the system console +#define con_debug common::ConsoleInterface::instance()->debugstream() +#else +#define con_debug if (0) *(std::ostream*)(0) +#endif + +namespace common { + +/// common interface for the client and server Console classes +class ConsoleInterface { +public: + /// default constructor + ConsoleInterface(); + + /// default destructor + virtual ~ConsoleInterface(); + + /// stream to send normal messages too + virtual std::ostream & messagestream() = 0; + + /// stream to send warning messages too + virtual std::ostream & warningstream() = 0; + + /// stream to send debug messages too + virtual std::ostream & debugstream() = 0; + + /// a pointer to the current console instance + static ConsoleInterface *instance(); + +private: + /// console singleton + static ConsoleInterface *consoleinterface_instance; +}; + +} // namespace common + +#endif // __INCLUDED_COMMON_CONSOLEINTERFACE_H__ + -- cgit v1.2.3