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 
235 class GraphIO
236 {
237 public:
238  typedef std::map<representation::Type, Writer::Ptr> WriterMap;
239  typedef std::map<representation::Type, Reader::Ptr> ReaderMap;
240  typedef std::map<representation::Suffix, representation::Type> SuffixMap;
241 
242  static std::string write(const std::string& filename, const BaseGraph::Ptr& graph, representation::Type format = representation::UNKNOWN);
243  static std::string write(const std::string& filename, const BaseGraph& graph, representation::Type format = representation::UNKNOWN);
244 
245  static void read(const std::string& filename, BaseGraph::Ptr graph, representation::Type format = representation::UNKNOWN);
246  static void read(const std::string& filename, BaseGraph& graph, representation::Type format = representation::UNKNOWN);
247 
248  static WriterMap getWriterMap() { return msWriters; }
249  static ReaderMap getReaderMap() { return msReaders; }
250  static SuffixMap getSuffixMap() { return msSuffixes; }
251 
252  static representation::Type getTypeFromSuffix(representation::Suffix suffix);
253  static representation::Type getTypeFromFilename(const std::string& filename);
254  static std::string appendSuffix(const std::string& filename, representation::Type format);
255  static representation::Suffix getSuffix(representation::Type format);
256 
257 private:
258  static WriterMap msWriters;
259  static ReaderMap msReaders;
260  static SuffixMap msSuffixes;
261 };
262 
263 } // end namespace io
264 } // end namespace graph_analysis
265 
266 #endif //GRAPH_ANALYSIS_IO_HPP
std::string Suffix
Definition: GraphIO.hpp:13
std::map< representation::Suffix, representation::Type > SuffixMap
Definition: GraphIO.hpp:240
std::map< representation::Type, Writer::Ptr > WriterMap
Definition: GraphIO.hpp:238
Main class for handling I/O for graphs.
Definition: GraphIO.hpp:235
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:249
Main namespace of the graph analysis library.
Definition: BFS.cpp:3
std::map< representation::Type, Reader::Ptr > ReaderMap
Definition: GraphIO.hpp:239
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:248
static SuffixMap getSuffixMap()
Definition: GraphIO.hpp:250
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