TimeTableCatalogFactory.hh
1.88 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* TimeTableCatalogFactory.hh
*
* Created on: 8 août 2013
* Author: CS
*/
#ifndef TIMETABLECATALOGFACTORY_HH_
#define TIMETABLECATALOGFACTORY_HH_
#include "AbstractReader.hh"
#include "AbstractWriter.hh"
#include <string>
#include <map>
#include <memory>
#include <mutex>
namespace TimeTableCatalog {
class TimeTableCatalogFactory {
public:
virtual ~TimeTableCatalogFactory();
/**
* Gets singleton instance.
*/
static TimeTableCatalogFactory& getInstance() {
std::call_once(_onceFlag, [] {
_instance.reset(new TimeTableCatalogFactory);
});
return *_instance.get();
}
/**
* Adds a possible tt reader.
*/
static void registerReader(const std::string& pKey,
AbstractReader* pReader);
/**
* Adds a possible tt writer.
*/
static void registerWriter(const std::string& pKey,
AbstractWriter* pWriter);
/**
* Automatically detects a tt type.
*/
std::string getReaderType(const std::string& pPath);
/**
* Checks a reader exists for this type.
*/
bool canRead(const std::string& pType) const;
/**
* Creates a reader of a given type.
*/
std::unique_ptr<AbstractReader> createReader(const std::string& pKey,
const std::string& pPath) const;
/**
* Creates a writer of a given type.
*/
std::unique_ptr<AbstractWriter> createWriter(const std::string& pKey,
const std::string& pPath, const std::string& pName = "") const;
/**
* Map of registered tt readers.
*/
static std::map<const std::string, AbstractReader*> _readers;
/**
* Map of registered tt writers.
*/
static std::map<const std::string, AbstractWriter*> _writers;
private:
TimeTableCatalogFactory();
/**
* Singleton unique instance
*/
static std::unique_ptr<TimeTableCatalogFactory> _instance;
/**
* Flag to guarantee singleton unicity.
*/
static std::once_flag _onceFlag;
};
} /* namespace TimeTableCatalog */
#endif /* TIMETABLECATALOGFACTORY_HH_ */