Gorgon Game Engine
DataExchange.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <numeric>
4 
5 namespace Gorgon {
6 
7 
12  class ExchangeData { // this class will be moved elsewhere
13  public:
14  virtual ~ExchangeData() {}
15 
17  virtual std::string Name() const = 0;
18 
20  virtual Resource::GID::Type Type() const = 0;
21 
23  virtual std::string Text() const {
24  return Name();
25  }
26  };
27 
31  class TextData : public ExchangeData {
32  public:
33  explicit TextData(std::string text = "") : text(text) {}
34 
36  void SetText(std::string value) {
37  text = value;
38  }
39 
41  std::string GetText() const {
42  return text;
43  }
44 
45  virtual std::string Name() const override {
46  return "Text";
47  }
48 
49  virtual std::string Text() const override {
50  return text;
51  }
52 
53  virtual Resource::GID::Type Type() const override {
54  return Resource::GID::Text;
55  }
56 
57  private:
58  std::string text;
59  };
60 
64  class FileData : public ExchangeData {
65  public:
68  Copy
69  };
70 
71  explicit FileData(std::vector<std::string> files ={}) : files(std::move(files)) {}
72 
73  explicit FileData(std::string file) : files({file}) {}
74 
76  void AddFile(std::string value) {
77  files.push_back(value);
78  }
79 
81  void RemoveFile(int ind) {
82  files.erase(files.begin()+ind);
83  }
84 
86  void Clear() {
87  files.clear();
88  }
89 
91  int GetSize() const {
92  return (int)files.size();
93  }
94 
96  std::string operator[] (int ind) const {
97  return files[ind];
98  }
99 
101  std::vector<std::string>::const_iterator begin() const {
102  return files.begin();
103  }
104 
106  std::vector<std::string>::const_iterator end() const {
107  return files.end();
108  }
109 
111  std::vector<std::string>::iterator begin() {
112  return files.begin();
113  }
114 
116  std::vector<std::string>::iterator end() {
117  return files.end();
118  }
119 
120  virtual std::string Name() const override {
121  return "File";
122  }
123 
124  virtual Resource::GID::Type Type() const override {
125  return Resource::GID::File;
126  }
127 
128  virtual std::string Text() const override {
129  return String::Join(files, "; ");
130  }
131 
133 
134  private:
135  std::vector<std::string> files;
136  };
137 
138 }
Gorgon::FileData::end
std::vector< std::string >::const_iterator end() const
To allow ranged based iteration.
Definition: DataExchange.h:106
Gorgon::Resource::GID::File
constexpr Type File
File.
Definition: GID.h:84
Gorgon::FileData::ExchangeAction
ExchangeAction
Definition: DataExchange.h:66
Gorgon::FileData::Copy
@ Copy
Definition: DataExchange.h:68
Gorgon::ExchangeData::Text
virtual std::string Text() const
Should return the textual representation of the data. A datatype can simply return its typename.
Definition: DataExchange.h:23
Gorgon::Resource::GID::Text
constexpr Type Text
Stores text data, no longer a resource.
Definition: GID.h:134
Gorgon::TextData::GetText
std::string GetText() const
Returns the text in this data.
Definition: DataExchange.h:41
Gorgon::TextData::Type
virtual Resource::GID::Type Type() const override
Should return the type id of the data.
Definition: DataExchange.h:53
Gorgon::ExchangeData::Type
virtual Resource::GID::Type Type() const =0
Should return the type id of the data.
Gorgon::FileData::FileData
FileData(std::string file)
Definition: DataExchange.h:73
Gorgon::FileData::end
std::vector< std::string >::iterator end()
To allow ranged based iteration.
Definition: DataExchange.h:116
Gorgon::FileData::Text
virtual std::string Text() const override
Should return the textual representation of the data. A datatype can simply return its typename.
Definition: DataExchange.h:128
Gorgon::String::Join
std::string Join(const T_ &vec, const std::string &glue=", ")
Joins a list of strings to a single string using the given glue text.
Definition: String.h:735
Gorgon::FileData::Name
virtual std::string Name() const override
Should return the name of the data type.
Definition: DataExchange.h:120
Gorgon::ExchangeData::~ExchangeData
virtual ~ExchangeData()
Definition: DataExchange.h:14
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::FileData::Clear
void Clear()
Clears the file list.
Definition: DataExchange.h:86
Gorgon::FileData::FileData
FileData(std::vector< std::string > files={})
Definition: DataExchange.h:71
Gorgon::FileData::operator[]
std::string operator[](int ind) const
Returns the file at the given index.
Definition: DataExchange.h:96
Gorgon::ExchangeData
Base object for data to be exchanged.
Definition: DataExchange.h:12
Gorgon::TextData
Stores text data for data exchange.
Definition: DataExchange.h:31
Gorgon::FileData::AddFile
void AddFile(std::string value)
Adds a new file to the list.
Definition: DataExchange.h:76
Gorgon::FileData::GetSize
int GetSize() const
Returns the number of files in the list.
Definition: DataExchange.h:91
Gorgon::FileData::Type
virtual Resource::GID::Type Type() const override
Should return the type id of the data.
Definition: DataExchange.h:124
Gorgon::ExchangeData::Name
virtual std::string Name() const =0
Should return the name of the data type.
Gorgon::TextData::Name
virtual std::string Name() const override
Should return the name of the data type.
Definition: DataExchange.h:45
Gorgon::FileData::Move
@ Move
Definition: DataExchange.h:67
Gorgon::FileData::begin
std::vector< std::string >::const_iterator begin() const
To allow ranged based iteration.
Definition: DataExchange.h:101
Gorgon::Resource::GID::Type
Type to store GID information.
Definition: GID.h:23
Gorgon::TextData::TextData
TextData(std::string text="")
Definition: DataExchange.h:33
Gorgon::FileData
Stores list of files for data exchange.
Definition: DataExchange.h:64
Gorgon::TextData::SetText
void SetText(std::string value)
Changes the text in this data.
Definition: DataExchange.h:36
Gorgon::FileData::RemoveFile
void RemoveFile(int ind)
Removes a file from the list.
Definition: DataExchange.h:81
Gorgon::FileData::Action
ExchangeAction Action
Definition: DataExchange.h:132
Gorgon::FileData::begin
std::vector< std::string >::iterator begin()
To allow ranged based iteration.
Definition: DataExchange.h:111
Gorgon::TextData::Text
virtual std::string Text() const override
Should return the textual representation of the data. A datatype can simply return its typename.
Definition: DataExchange.h:49