Visualization Library 2.1.0

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
ioVLX.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 LoadWriterVLX_INCLUDE_ONCE
33 #define LoadWriterVLX_INCLUDE_ONCE
34 
35 #include <vlX/ClassWrapper.hpp>
36 #include <vlX/Registry.hpp>
37 #include <vlX/Serializer.hpp>
38 #include <vlX/Value.hpp>
39 #include <vlX/vlxutils.hpp>
42 #include <vlCore/DiskFile.hpp>
43 
44 namespace vlX
45 {
46  //-----------------------------------------------------------------------------
47 
53  VLX_EXPORT bool saveVLT(const vl::String& file, const vl::ResourceDatabase*);
55  VLX_EXPORT bool saveVLB(const vl::String& file, const vl::ResourceDatabase*);
56  VLX_EXPORT bool isVLT(vl::VirtualFile* file);
57  VLX_EXPORT bool isVLT(const vl::String& file);
58  VLX_EXPORT bool isVLB(vl::VirtualFile* file);
59  VLX_EXPORT bool isVLB(const vl::String& file);
60 
61  //---------------------------------------------------------------------------
62  // LoadWriterVLX
63  //---------------------------------------------------------------------------
68  {
70 
71  public:
72  LoadWriterVLX(): vl::ResourceLoadWriter("|vlt|vlb|", "|vlt|vlb|") {}
73 
75  {
76  if (isVLT(path))
77  return loadVLT(path);
78  else
79  if (isVLB(path))
80  return loadVLB(path);
81  else
82  return NULL;
83  }
84 
86  {
87  if (isVLT(file))
88  return loadVLT(file);
89  else
90  if (isVLB(file))
91  return loadVLB(file);
92  else
93  return NULL;
94  }
95 
96  bool writeResource(const vl::String& path, vl::ResourceDatabase* res_db) const
97  {
98  if (path.extractFileExtension().toLowerCase() == "vlt")
99  return saveVLT(path, res_db);
100  else
101  if (path.extractFileExtension().toLowerCase() == "vlb")
102  return saveVLB(path, res_db);
103  else
104  return false;
105  }
106 
108  {
109  if (file->path().extractFileExtension().toLowerCase() == "vlt")
110  return saveVLT(file, res_db);
111  else
112  if (file->path().extractFileExtension().toLowerCase() == "vlb")
113  return saveVLB(file, res_db);
114  else
115  return false;
116  }
117  };
118 //-----------------------------------------------------------------------------
119 }
120 
121 #endif
String toLowerCase() const
Returns the lower-case version of a String.
Definition: String.cpp:755
VLX_EXPORT bool saveVLT(vl::VirtualFile *file, const vl::ResourceDatabase *)
Definition: ioVLX.cpp:90
String extractFileExtension(bool require_dot=true) const
If the String contains a file name or file path the function returns the extension of the file...
Definition: String.cpp:857
An abstract class representing a file.
Definition: VirtualFile.hpp:60
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
bool writeResource(vl::VirtualFile *file, vl::ResourceDatabase *res_db) const
Definition: ioVLX.hpp:107
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
const String & path() const
Returns the path of the file.
Definition: VirtualFile.hpp:98
Visualization Library main namespace.
VLX_EXPORT bool isVLT(vl::VirtualFile *file)
Definition: ioVLX.cpp:132
A vl::ResourceLoadWriter capable of reading Visualization Library&#39;s VLT and VLB files.
Definition: ioVLX.hpp:67
vl::ref< vl::ResourceDatabase > loadResource(vl::VirtualFile *file) const
Definition: ioVLX.hpp:85
VLX_EXPORT bool isVLB(vl::VirtualFile *file)
Definition: ioVLX.cpp:151
#define NULL
Definition: OpenGLDefs.hpp:81
VLX_EXPORT vl::ref< vl::ResourceDatabase > loadVLT(vl::VirtualFile *file)
Definition: ioVLX.cpp:44
vl::ref< vl::ResourceDatabase > loadResource(const vl::String &path) const
Definition: ioVLX.hpp:74
bool writeResource(const vl::String &path, vl::ResourceDatabase *res_db) const
Definition: ioVLX.hpp:96
VLX_EXPORT bool saveVLB(vl::VirtualFile *file, const vl::ResourceDatabase *)
Definition: ioVLX.cpp:111
ResourceLoadWriter(const String &load_extensions, const String &write_extensions)
The ResourceLoadWriter class is an abstract class used to implement read/write support for one or mor...
VLX_EXPORT vl::ref< vl::ResourceDatabase > loadVLB(vl::VirtualFile *file)
Definition: ioVLX.cpp:67
The ResourceDatabase class contains and manipulates a set of resources.