Neo  0.5.0
Developer Documentation
DataLoader.h
Go to the documentation of this file.
1 //========================================================================
2 // Copyright (c) 2003-2011 Anael Seghezzi <www.maratis3d.com>
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 //
8 // Permission is granted to anyone to use this software for any purpose,
9 // including commercial applications, and to alter it and redistribute it
10 // freely, subject to the following restrictions:
11 //
12 // 1. The origin of this software must not be misrepresented; you must not
13 // claim that you wrote the original software. If you use this software
14 // in a product, an acknowledgment in the product documentation would
15 // be appreciated but is not required.
16 //
17 // 2. Altered source versions must be plainly marked as such, and must not
18 // be misrepresented as being the original software.
19 //
20 // 3. This notice may not be removed or altered from any source
21 // distribution.
22 //
23 //========================================================================
24 
25 
26 #ifndef __DATA_LOADER_H
27 #define __DATA_LOADER_H
28 
29 #include <functional>
30 
31 namespace Neo
32 {
33 
34 // Data loader
35 template<class T> class DataLoader
36 {
37 private:
38 
39  typedef std::function<bool(const char* filename, const char* type, T* data)> save_function_t;
40  typedef std::function<bool(const char* filename, T* data)> load_function_t;
41 
42  vector<load_function_t> m_loaders;
43  vector<save_function_t> m_savers;
44 
45 public:
46 
47  // Data loader
48  DataLoader(void)
49  {}
50 
52  {
53  clear();
54  }
55 
56  void clear(void)
57  {
58  m_loaders.clear();
59  m_savers.clear();
60  }
61 
62  void addLoader(load_function_t function)
63  {
64  m_loaders.push_back(function);
65  }
66 
67  void addSaver(save_function_t function)
68  {
69  m_savers.push_back(function);
70  }
71 
72  bool loadData(const char * filename, T* data)
73  {
74  for(load_function_t f : m_loaders)
75  {
76  if(f(filename, data))
77  return true;
78  }
79 
80  return false;
81  }
82 
83 
84  bool saveData(const char* filename, const char* type, T* data)
85  {
86  for(save_function_t f : m_savers)
87  {
88  if(f(filename, type, data))
89  return true;
90  }
91 
92  return false;
93  }
94 };
95 }
96 #endif
void addLoader(load_function_t function)
Definition: DataLoader.h:62
bool loadData(const char *filename, T *data)
Definition: DataLoader.h:72
Definition: DataLoader.h:35
void addSaver(save_function_t function)
Definition: DataLoader.h:67
~DataLoader(void)
Definition: DataLoader.h:51
DataLoader(void)
Definition: DataLoader.h:48
void clear(void)
Definition: DataLoader.h:56
Definition: Color.h:29
bool saveData(const char *filename, const char *type, T *data)
Definition: DataLoader.h:84