root/trunk/libs/hydrogen/include/hydrogen/Object.h @ 148

Revision 148, 3.1 KB (checked in by smoors, 5 years ago)

added fix for mac os x build

Line 
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 *
5 * http://www.hydrogen-music.org
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY, without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 *
21 */
22
23#ifndef H2_OBJECT_H
24#define H2_OBJECT_H
25
26#ifdef check
27#undef check
28#endif
29
30
31#include <QtGui>
32#include <map>
33#include <vector>
34#include <sstream>
35#include <pthread.h>
36
37
38// LOG MACROS
39
40#define _INFOLOG(x) Logger::get_instance()->info_log( __PRETTY_FUNCTION__, "", x );
41#define _WARNINGLOG(x) Logger::get_instance()->warning_log( __PRETTY_FUNCTION__, "", x );
42#define _ERRORLOG(x) Logger::get_instance()->error_log( __PRETTY_FUNCTION__, "", x );
43
44#define INFOLOG(x) Logger::get_instance()->info_log( __FUNCTION__, get_class_name(), x );
45#define WARNINGLOG(x) Logger::get_instance()->warning_log( __FUNCTION__, get_class_name(), x );
46#define ERRORLOG(x) Logger::get_instance()->error_log( __FUNCTION__, get_class_name(), x );
47
48
49
50class Object;
51
52/**
53 * Class for writing logs to the console
54 */
55class Logger
56{
57public:
58        bool __use_file;
59        bool __running;
60        std::vector<QString> __msg_queue;
61        pthread_mutex_t __logger_mutex;
62
63        static Logger* get_instance();
64
65        /** Destructor */
66        ~Logger();
67
68        void info_log( const char* funcname, const QString& class_name, const QString& msg );
69        void warning_log( const char* funcname, const QString& class_name, const QString& msg );
70        void error_log( const char* funcname, const QString& class_name, const QString& msg );
71
72private:
73        static Logger *__instance;
74
75        /** Constructor */
76        Logger();
77
78
79};
80
81
82/**
83 * Base class.
84 */
85class Object
86{
87public:
88        static bool __use_log;
89
90        /** Constructor */
91        Object( const QString& className );
92        Object( const Object& obj );
93
94        /** Destructor */
95        virtual ~Object();
96
97        const QString& get_class_name() const {
98                return __class_name;
99        }
100
101        static int get_objects_number();
102        static void print_object_map();
103        static void use_verbose_log( bool verbose );
104        static bool is_using_verbose_log();
105
106private:
107        static unsigned __objects;
108        static std::map<QString, int> __object_map;
109        Logger *__logger;
110        QString __class_name;
111};
112
113
114// some useful functions..
115
116template <class T>
117inline QString to_string( const T& t )
118{
119        std::ostringstream osstream;
120        osstream << t;
121
122        return QString( osstream.str().c_str() );
123}
124
125inline int string_to_int( const QString& str )
126{
127        std::istringstream isstream( str.toStdString() );
128        int t;
129        isstream >> t;
130        return t;
131}
132inline float string_to_float( const QString& str )
133{
134        std::istringstream isstream( str.toStdString() );
135        float t;
136        isstream >> t;
137        return t;
138}
139
140#endif
Note: See TracBrowser for help on using the browser.