Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[libiodata] Remove qmlog dependency, add log macros, simplify includes
  • Loading branch information
Petri M. Gerdt committed Apr 18, 2013
1 parent bdcb4d8 commit 404a350
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 70 deletions.
1 change: 0 additions & 1 deletion H/iodata

This file was deleted.

1 change: 0 additions & 1 deletion H/iodata-qt5

This file was deleted.

2 changes: 2 additions & 0 deletions root.pro
Expand Up @@ -12,3 +12,5 @@ equals(QT_MAJOR_VERSION, 5) {
}

INSTALLS = prf

OTHER_FILES += rpm/*.spec
1 change: 0 additions & 1 deletion rpm/libiodata-qt5.spec
Expand Up @@ -11,7 +11,6 @@ Source0: %{_name}-%{version}.tar.bz2
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: bison
BuildRequires: flex
BuildRequires: libqmlog-qt5-devel

%description
This package provides a library for writing and reading structured data.
Expand Down
76 changes: 76 additions & 0 deletions src/log.h
@@ -0,0 +1,76 @@
#ifndef LOG_H
#define LOG_H

#include <QtGlobal>
#include <cassert>
#include <cstdio>

#define LOG_NONE 0
#define LOG_ASSERT 1
#define LOG_CRITICAL 2
#define LOG_ERROR 3
#define LOG_WARNING 4
#define LOG_NOTICE 5
#define LOG_INFO 6
#define LOG_DEBUG 7
#define LOG_FULL LOG_DEBUG

#define LOG_LEVEL LOG_WARNING

#if LOG_LEVEL >= LOG_DEBUG
# define log_debug(FMT,ARGS...) \
do { \
printf("DEBUG: %s:%d: %s", __FILE__, __LINE__, Q_FUNC_INFO); \
if (strlen(""FMT) > 0) \
printf(":\n- "FMT"\n", ## ARGS); \
else \
printf("\n"); \
} while(0)
#else
# define log_debug(FMT,ARGS...) do { } while(0)
#endif

#if LOG_LEVEL >= LOG_INFO
# define log_info(FMT,ARGS...) do { fprintf(stderr, "INFO: "FMT"\n", ## ARGS); } while(0)
#else
# define log_info(FMT,ARGS...) do { } while(0)
#endif

#if LOG_LEVEL >= LOG_INFO
# define log_notice(FMT,ARGS...) do { fprintf(stderr, "NOTICE: "FMT"\n", ## ARGS); } while(0)
#else
# define log_notice(FMT,ARGS...) do { } while(0)
#endif

#if LOG_LEVEL >= LOG_WARNING
# define log_warning(FMT,ARGS...) do { fprintf(stderr, "WARNING: "FMT"\n", ## ARGS); } while(0)
#else
# define log_warning(FMT,ARGS...) do { } while(0)
#endif

#if LOG_LEVEL >= LOG_ERROR
# define log_error(FMT,ARGS...) do { fprintf(stderr, "ERROR: "FMT"\n", ## ARGS); } while(0)
#else
# define log_error(FMT,ARGS...) do { } while(0)
#endif

#if LOG_LEVEL >= LOG_CRITICAL
# define log_critical(FMT,ARGS...) do { fprintf(stderr, "CRITICAL: "FMT"\n", ## ARGS); } while(0)
#else
# define log_critical(FMT,ARGS...) do { } while(0)
#endif

#if LOG_LEVEL >= LOG_ASSERT
# define log_assert(COND, ARGS...) \
do { \
if (!(COND)) \
fprintf(stderr, "ASSERT: "ARGS); \
assert(COND); \
} while(0)
# define log_abort(FMT,ARGS...) do { fprintf(stderr, "ABORT: "FMT"\n", ## ARGS); assert(0); } while(0)
#else
# define log_assert(COND, ARGS...) do { assert(COND); } while(0)
# define log_abort(FMT,ARGS...) do { assert(0); } while(0)
#endif

#endif // LOG_H
8 changes: 1 addition & 7 deletions src/misc.cpp
Expand Up @@ -4,14 +4,8 @@

using namespace std ;

#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <qmlog-qt5>
#else
#include <qmlog>
#endif

#include "misc.h"
#include "log.h"

string str_vprintf(const char *format, va_list varg)
{
Expand Down
5 changes: 1 addition & 4 deletions src/src.pro
Expand Up @@ -2,10 +2,7 @@ VERSION = 0.$$(IODATA_VERSION)
TEMPLATE=lib
QT -= gui

equals(QT_MAJOR_VERSION, 4): CONFIG += qmlog
equals(QT_MAJOR_VERSION, 5): CONFIG += qmlog-qt5

INCLUDEPATH += ../H
HEADERS = iodata.h validator.h storage.h misc.h log.h
SOURCES = iodata.cpp validator.cpp storage.cpp misc.cpp

equals(QT_MAJOR_VERSION, 4): TARGET = iodata
Expand Down
8 changes: 1 addition & 7 deletions src/storage.cpp
Expand Up @@ -30,13 +30,7 @@
#include <sstream>
using namespace std ;

#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <qmlog-qt5>
#else
#include <qmlog>
#endif

#include "log.h"
#include "iodata.h"
#include "validator.h"
#include "storage.h"
Expand Down
9 changes: 1 addition & 8 deletions src/storage.h
Expand Up @@ -32,14 +32,7 @@
#include <vector>
#include <string>

#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <iodata-qt5/iodata.h>
#include <iodata-qt5/validator.h>
#else
#include <iodata/iodata.h>
#include <iodata/validator.h>
#endif
#include "iodata.h"

namespace iodata { class storage ; }

Expand Down
7 changes: 1 addition & 6 deletions src/validator.cpp
Expand Up @@ -25,12 +25,7 @@
#include <iostream>
using namespace std ;

#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <qmlog-qt5>
#else
#include <qmlog>
#endif
#include "log.h"

#include "iodata.h"
#include "validator.h"
Expand Down
7 changes: 1 addition & 6 deletions src/validator.h
Expand Up @@ -34,12 +34,7 @@
#include <typeinfo>
using namespace std ;

#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <iodata-qt5/iodata.h>
#else
#include <iodata/iodata.h>
#endif
#include "iodata.h"

namespace iodata
{
Expand Down
10 changes: 2 additions & 8 deletions tests/iodata-test.cpp
Expand Up @@ -5,14 +5,8 @@
#include <sstream>
using namespace std ;

#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <qmlog-qt5>
#include <iodata-qt5/iodata.h>
#else
#include <qmlog>
#include <iodata/iodata.h>
#endif
#include "../src/iodata.h"
#include "../src/log.h"

int trivial(int ac, char **av) ;
int storage(int ac, char **av) ;
Expand Down
5 changes: 1 addition & 4 deletions tests/tests.pro
Expand Up @@ -4,20 +4,17 @@ QT -= gui
equals(QT_MAJOR_VERSION, 4): TARGET = iodata-test
equals(QT_MAJOR_VERSION, 5): TARGET = iodata-qt5-test

equals(QT_MAJOR_VERSION, 4): CONFIG += qmlog
equals(QT_MAJOR_VERSION, 5): CONFIG += qmlog-qt5

INSTALLS = target tests

equals(QT_MAJOR_VERSION, 4): LIBS += -liodata
equals(QT_MAJOR_VERSION, 5): LIBS += -liodata-qt5
QMAKE_LIBDIR_FLAGS += -L../src
INCLUDEPATH += ../H

SOURCES = iodata-test.cpp

equals(QT_MAJOR_VERSION, 4): tests.path = /usr/share/iodata-tests
equals(QT_MAJOR_VERSION, 5): tests.path = /usr/share/iodata-qt5-tests

tests.files = tests.xml

target.path = /usr/bin
17 changes: 4 additions & 13 deletions type-to-cxx/type-to-cxx.cpp
Expand Up @@ -3,18 +3,10 @@ using namespace std ;

#include <argp.h>

#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <qmlog-qt5>
#include <iodata-qt5/iodata.h>
#include <iodata-qt5/validator.h>
#include <iodata-qt5/storage.h>
#else
#include <qmlog>
#include <iodata/iodata.h>
#include <iodata/validator.h>
#include <iodata/storage.h>
#endif
#include "../src/iodata.h"
#include "../src/validator.h"
#include "../src/storage.h"
#include "../src/log.h"

void dump_h(ostringstream &h, iodata::validator *v)
{
Expand Down Expand Up @@ -113,7 +105,6 @@ void dump_cpp(ostringstream &cpp, iodata::validator *v)

int main_try(int ac, char **av)
{
qmlog::enable() ;
string c_output, h_output ;
vector<string> input ;

Expand Down
4 changes: 0 additions & 4 deletions type-to-cxx/type-to-cxx.pro
Expand Up @@ -4,15 +4,11 @@ QT -= gui
equals(QT_MAJOR_VERSION, 4): TARGET = iodata-type-to-c++
equals(QT_MAJOR_VERSION, 5): TARGET = iodata-qt5-type-to-c++

equals(QT_MAJOR_VERSION, 4): CONFIG += qmlog
equals(QT_MAJOR_VERSION, 5): CONFIG += qmlog-qt5

INSTALLS = target

equals(QT_MAJOR_VERSION, 4): LIBS += -liodata -lcrypt
equals(QT_MAJOR_VERSION, 5): LIBS += -liodata-qt5 -lcrypt
QMAKE_LIBDIR_FLAGS += -L../src
INCLUDEPATH += ../H

SOURCES = type-to-cxx.cpp

Expand Down

0 comments on commit 404a350

Please sign in to comment.