Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
LoadWriterManager.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef LoadWriterManager_INCLUDE_ONCE
33 #define LoadWriterManager_INCLUDE_ONCE
34 
37 #include <vlCore/VirtualFile.hpp>
38 #include <vlCore/MemoryFile.hpp>
40 
41 namespace vl
42 {
44  class LoadCallback: public Object
45  {
46  public:
47  virtual void operator()(ResourceDatabase* db) = 0;
48  };
49 
51  class WriteCallback: public Object
52  {
53  public:
54  virtual void operator()(ResourceDatabase* db) = 0;
55  };
56 
61  {
63 
64  public:
66  {
67  VL_DEBUG_SET_OBJECT_NAME()
68  }
69 
71 
73  std::vector< ref<ResourceLoadWriter> >& loadWriters() { return mLoadWriters; }
74 
76  const std::vector< ref<ResourceLoadWriter> >& loadWriters() const { return mLoadWriters; }
77 
79  template<class T>
81  {
82  for(size_t i=0; i<loadWriters().size(); ++i)
83  {
84  T* load_writer = loadWriters()[i]->as<T>();
85  if (load_writer)
86  return load_writer;
87  }
88  return NULL;
89  }
90 
92  bool canLoad(const String& path) const { return findLoader(path) != NULL; }
93 
95  bool canLoad(VirtualFile* file) const { return findLoader(file->path()) != NULL; }
96 
98  bool canWrite(const String& path) const { return findWriter(path) != NULL; }
99 
101  bool canWrite(VirtualFile* file) const { return findWriter(file->path()) != NULL; }
102 
104  const ResourceLoadWriter* findLoader(const String& path) const;
105 
107  const ResourceLoadWriter* findWriter(const String& path) const;
108 
110  const ResourceLoadWriter* findLoader(VirtualFile* file) const;
111 
113  const ResourceLoadWriter* findWriter(VirtualFile* file) const;
114 
116  ref<ResourceDatabase> loadResource(const String& path, bool quick=true) const;
117 
119  ref<ResourceDatabase> loadResource(VirtualFile* file, bool quick=true) const;
120 
122  bool writeResource(const String& path, ResourceDatabase* resource) const;
123 
125  bool writeResource(VirtualFile* file, ResourceDatabase* resource) const;
126 
127  const std::vector< ref<LoadCallback> >& loadCallbacks() const { return mLoadCallbacks; }
128 
129  const std::vector< ref<WriteCallback> >& writeCallbacks() const { return mWriteCallbacks; }
130 
131  std::vector< ref<LoadCallback> >& loadCallbacks() { return mLoadCallbacks; }
132 
133  std::vector< ref<WriteCallback> >& writeCallbacks() { return mWriteCallbacks; }
134 
135  protected:
136  std::vector< ref<ResourceLoadWriter> > mLoadWriters;
137  std::vector< ref<LoadCallback> > mLoadCallbacks;
138  std::vector< ref<WriteCallback> > mWriteCallbacks;
139  };
140 
143 
146 
149 }
150 
151 #endif
bool canWrite(VirtualFile *file) const
Returns true if there is a ResourceLoadWriter registered to write the specified file.
std::vector< ref< LoadCallback > > mLoadCallbacks
Defines an operation to be exectued to a ResourceDatabase as soon as its loaded, see also LoadWriterM...
An abstract class representing a file.
Definition: VirtualFile.hpp:60
const std::vector< ref< WriteCallback > > & writeCallbacks() const
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
const std::vector< ref< LoadCallback > > & loadCallbacks() const
The LoadWriterManager class loads and writes resources using the registered ResourceLoadWriter object...
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
VLCORE_EXPORT ref< ResourceDatabase > loadResource(const String &path, bool quick=true)
Short version of defLoadWriterManager()->loadResource(path, quick).
const String & path() const
Returns the path of the file.
Definition: VirtualFile.hpp:98
Visualization Library main namespace.
std::vector< ref< LoadCallback > > & loadCallbacks()
The base class for all the reference counted objects.
Definition: Object.hpp:158
std::vector< ref< ResourceLoadWriter > > & loadWriters()
Returns the set of registered ResourceLoadWriter objects.
#define NULL
Definition: OpenGLDefs.hpp:81
Defines an operation to be exectued to a ResourceDatabase just before it is written, see also LoadWriterManager, LoadCallback.
bool canWrite(const String &path) const
Returns true if there is a ResourceLoadWriter registered to write the specified path or extension...
bool canLoad(const String &path) const
Returns true if there is a ResourceLoadWriter registered to load the specified path or extension...
VLCORE_EXPORT void setDefLoadWriterManager(LoadWriterManager *lwm)
Sets the default LoadWriterManager used by Visualization Library.
Definition: pimpl.cpp:86
virtual void operator()(ResourceDatabase *db)=0
bool canLoad(VirtualFile *file) const
Returns true if there is a ResourceLoadWriter registered to load the specified file.
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
std::vector< ref< WriteCallback > > & writeCallbacks()
std::vector< ref< ResourceLoadWriter > > mLoadWriters
The ResourceLoadWriter class is an abstract class used to implement read/write support for one or mor...
const std::vector< ref< ResourceLoadWriter > > & loadWriters() const
Returns the set of registered ResourceLoadWriter objects.
VLCORE_EXPORT bool writeResource(const String &path, ResourceDatabase *resource)
Short version of defLoadWriterManager()->writeResource(path, resource).
T * loadWriter()
Returns the first ResourceLoadWriter of the specified type found.
VLCORE_EXPORT LoadWriterManager * defLoadWriterManager()
Returs the default LoadWriterManager used by Visualization Library.
Definition: pimpl.cpp:82
void registerLoadWriter(ResourceLoadWriter *rlw)
Utility function, equivalent to defLoadWriterManager()->registerLoadWriter(rlw).
The ResourceDatabase class contains and manipulates a set of resources.
void registerLoadWriter(ResourceLoadWriter *)
std::vector< ref< WriteCallback > > mWriteCallbacks