summaryrefslogtreecommitdiff
path: root/src/include/iofactory.h
blob: 24dfe9fbbfe4b9035d97058c0ba70f5b4ae0d56c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
 *  @file iofactory.h
 *  @brief  Declaration of the IOFactory class.
 *  @author Andreas Aardal Hanssen
 *  @date 2002, 2003
 */

#ifndef IOFACTORY_H_INCLUDED
#define IOFACTORY_H_INCLUDED

#include "iodevice.h"

#include <map>
#include <string>

namespace Binc {
  class IOFactory {
  public:
    ~IOFactory();

    static void addDevice(IODevice *dev);
    static IOFactory &getInstance();
    static IODevice &getClient();
    static IODevice &getLogger();

  private:
    IOFactory();

    std::map<std::string, IODevice *> devices;
  };
}

#define bincClient IOFactory::getClient()

#if defined(DEBUG)
// #define bincError if (false) std::cout
#define bincError std::cerr
// #define bincWarning if (false) std::cout
#define bincWarning std::cerr
#define bincDebug   std::cerr
// #define bincDebug if (false) std::cout
#else
#define bincError                                                        \
  IOFactory::getLogger().setOutputLevel(IODevice::LogLevel::ErrorLevel); \
  IOFactory::getLogger()
#define bincWarning                                                        \
  IOFactory::getLogger().setOutputLevel(IODevice::LogLevel::WarningLevel); \
  IOFactory::getLogger()
#define bincDebug                                                        \
  IOFactory::getLogger().setOutputLevel(IODevice::LogLevel::DebugLevel); \
  IOFactory::getLogger()
#endif

#define bincLog                                                         \
  IOFactory::getLogger().setOutputLevel(IODevice::LogLevel::InfoLevel); \
  IOFactory::getLogger()

#endif