graph_analysis
GraphIO.hpp
Go to the documentation of this file.
1 #ifndef GRAPH_ANALYSIS_IO_HPP
2 #define GRAPH_ANALYSIS_IO_HPP
3 
4 #include <stdexcept>
5 #include "Graph.hpp"
6 
7 namespace graph_analysis {
8 
9 namespace representation {
10 
12 
13 typedef std::string Suffix;
14 
15 extern std::map<Type, std::string> TypeTxt;
16 
17 } // end namespace representation
18 
19 namespace io {
20 
22 const std::string CLASS("0");
23 const std::string LABEL("1");
24 
30 class Writer
31 {
32 public:
33  typedef shared_ptr<Writer> Ptr;
34 
35  virtual ~Writer() {}
36 
42  void write(const std::string& filename, const BaseGraph& graph) const;
43 
48  virtual void write(const std::string& filename, const BaseGraph::Ptr& graph) const { (void)filename; (void)graph; throw std::runtime_error("Writer: writer not implemented"); }
49 };
50 
56 class Reader
57 {
58 public:
59  typedef shared_ptr<Reader> Ptr;
60 
61  virtual ~Reader() {}
62 
63  void read(const std::string& filename, BaseGraph& graph);
64 
65  virtual void read(const std::string& filename, BaseGraph::Ptr graph) { (void) filename; (void) graph; throw std::runtime_error("Reader: reader not implemented"); }
66 
70  void setUuid(const GraphElement::Ptr& element, const std::string& uuid) const { element->setUuid(uuid); }
71 };
72 
246 class GraphIO
247 {
248 public:
249  typedef std::map<representation::Type, Writer::Ptr> WriterMap;
250  typedef std::map<representation::Type, Reader::Ptr> ReaderMap;
251  typedef std::map<representation::Suffix, representation::Type> SuffixMap;
252 
253  static std::string write(const std::string& filename, const BaseGraph::Ptr& graph, representation::Type format = representation::UNKNOWN);
254  static std::string write(const std::string& filename, const BaseGraph& graph, representation::Type format = representation::UNKNOWN);
255 
256  static void read(const std::string& filename, BaseGraph::Ptr graph, representation::Type format = representation::UNKNOWN);
257  static void read(const std::string& filename, BaseGraph& graph, representation::Type format = representation::UNKNOWN);
258 
259  static WriterMap getWriterMap() { return msWriters; }
260  static ReaderMap getReaderMap() { return msReaders; }
261  static SuffixMap getSuffixMap() { return msSuffixes; }
262 
263  static representation::Type getTypeFromSuffix(representation::Suffix suffix);
264  static representation::Type getTypeFromFilename(const std::string& filename);
265  static std::string appendSuffix(const std::string& filename, representation::Type format);
266  static representation::Suffix getSuffix(representation::Type format);
267 
268 private:
269  static WriterMap msWriters;
270  static ReaderMap msReaders;
271  static SuffixMap msSuffixes;
272 };
273 
274 } // end namespace io
275 } // end namespace graph_analysis
276 
277 #endif //GRAPH_ANALYSIS_IO_HPP
std::string Suffix
Definition: GraphIO.hpp:13
std::map< representation::Suffix, representation::Type > SuffixMap
Definition: GraphIO.hpp:251
std::map< representation::Type, Writer::Ptr > WriterMap
Definition: GraphIO.hpp:249
Main class for handling I/O for graphs.
Definition: GraphIO.hpp:246
Definition: GraphIO.hpp:11
shared_ptr< Reader > Ptr
Definition: GraphIO.hpp:59
Interface for Reader implementation that perform custom graph deserialization.
Definition: GraphIO.hpp:56
virtual ~Writer()
Definition: GraphIO.hpp:35
General Graph template that should be implemented to wrap specific graph library functionality We ass...
Definition: BaseGraph.hpp:27
virtual ~Reader()
Definition: GraphIO.hpp:61
shared_ptr< Writer > Ptr
Definition: GraphIO.hpp:33
static ReaderMap getReaderMap()
Definition: GraphIO.hpp:260
Main namespace of the graph analysis library.
Definition: BFS.cpp:3
std::map< representation::Type, Reader::Ptr > ReaderMap
Definition: GraphIO.hpp:250
Definition: GraphIO.hpp:11
const std::string LABEL("1")
Definition: GraphIO.hpp:11
shared_ptr< GraphElement > Ptr
Definition: GraphElement.hpp:46
Interface for Writer implementations that perform custom graph serialization.
Definition: GraphIO.hpp:30
void setUuid(const GraphElement::Ptr &element, const std::string &uuid) const
Definition: GraphIO.hpp:70
Definition: GraphIO.hpp:11
virtual void write(const std::string &filename, const BaseGraph::Ptr &graph) const
Definition: GraphIO.hpp:48
static WriterMap getWriterMap()
Definition: GraphIO.hpp:259
static SuffixMap getSuffixMap()
Definition: GraphIO.hpp:261
Definition: GraphIO.hpp:11
virtual void read(const std::string &filename, BaseGraph::Ptr graph)
Definition: GraphIO.hpp:65
shared_ptr< BaseGraph > Ptr
Definition: BaseGraph.hpp:34
const std::string CLASS("0")
GEXF reader/writer common conventions.
Type
Definition: GraphIO.hpp:11
std::map< Type, std::string > TypeTxt
Definition: GraphIO.cpp:20