Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics
[Home] [Tutorials] [All Classes] [Grouped Classes]

X:/dropbox/visualizationlibrary/src/vlGraphics/plugins/ioVLX.cpp

Go to the documentation of this file.
00001 /**************************************************************************************/
00002 /*                                                                                    */
00003 /*  Visualization Library                                                             */
00004 /*  http://www.visualizationlibrary.org                                               */
00005 /*                                                                                    */
00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
00007 /*  All rights reserved.                                                              */
00008 /*                                                                                    */
00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
00010 /*  are permitted provided that the following conditions are met:                     */
00011 /*                                                                                    */
00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
00013 /*  list of conditions and the following disclaimer.                                  */
00014 /*                                                                                    */
00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
00017 /*  other materials provided with the distribution.                                   */
00018 /*                                                                                    */
00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
00029 /*                                                                                    */
00030 /**************************************************************************************/
00031 
00032 #include <vlGraphics/plugins/ioVLX.hpp>
00033 #include <vlCore/Time.hpp>
00034 
00035 using namespace vl;
00036 
00037 //-----------------------------------------------------------------------------
00038 ref<ResourceDatabase> vl::loadVLT(const String& path)
00039 {
00040   ref<VirtualFile> file = vl::locateFile(path);
00041   return loadVLT(file.get());
00042 }
00043 //-----------------------------------------------------------------------------
00044 ref<ResourceDatabase> vl::loadVLT(VirtualFile* file)
00045 {
00046   VLXSerializer serializer;
00047 
00048   ref<Object> obj = serializer.loadVLT(file);
00049 
00050   if (serializer.error())
00051     Log::error( Say("vl::loadVLT : VLXSerializer reported: %s.\n") << serializer.errorString() );
00052 
00053   if (!obj)
00054     return NULL;
00055 
00056   ref<ResourceDatabase> res_db = obj->as<ResourceDatabase>();
00057 
00058   return res_db;
00059 }
00060 //-----------------------------------------------------------------------------
00061 ref<ResourceDatabase> vl::loadVLB(const String& path)
00062 {
00063   ref<VirtualFile> file = vl::locateFile(path);
00064   return loadVLB(file.get());
00065 }
00066 //-----------------------------------------------------------------------------
00067 ref<ResourceDatabase> vl::loadVLB(VirtualFile* file)
00068 {
00069   VLXSerializer serializer;
00070 
00071   ref<Object> obj = serializer.loadVLB(file);
00072 
00073   if (serializer.error())
00074     Log::error( Say("vl::loadVLB : VLXSerializer reported: %s.\n") << serializer.errorString() );
00075 
00076   if (!obj)
00077     return NULL;
00078 
00079   ref<ResourceDatabase> res_db = obj->as<ResourceDatabase>();
00080 
00081   return res_db;
00082 }
00083 //-----------------------------------------------------------------------------
00084 bool vl::saveVLT(const String& path, const ResourceDatabase* res_db)
00085 {
00086   ref<DiskFile> file = new DiskFile(path);
00087   return saveVLT(file.get(), res_db);
00088 }
00089 //-----------------------------------------------------------------------------
00090 bool vl::saveVLT(VirtualFile* file, const ResourceDatabase* res_db)
00091 {
00092   VL_CHECK(res_db);
00093   if (!res_db)
00094     return false;
00095 
00096   VLXSerializer serializer;
00097   serializer.saveVLT( file, res_db );
00098 
00099   if (serializer.error())
00100     Log::error( Say("vl::saveVLT : VLXSerializer reported: %s.\n") << serializer.errorString() );
00101 
00102   return serializer.error() == VLXSerializer::NoError;
00103 }
00104 //-----------------------------------------------------------------------------
00105 bool vl::saveVLB(const String& path, const ResourceDatabase* res_db)
00106 {
00107   ref<DiskFile> file = new DiskFile(path);
00108   return saveVLB(file.get(), res_db);
00109 }
00110 //-----------------------------------------------------------------------------
00111 bool vl::saveVLB(VirtualFile* file, const ResourceDatabase* res_db)
00112 {
00113   VL_CHECK(res_db);
00114   if (!res_db)
00115     return false;
00116 
00117   VLXSerializer serializer;
00118   serializer.saveVLB( file, res_db );
00119 
00120   if (serializer.error())
00121     Log::error( Say("vl::saveVLB : VLXSerializer reported: %s.\n") << serializer.errorString() );
00122 
00123   return serializer.error() == VLXSerializer::NoError;
00124 }
00125 //-----------------------------------------------------------------------------
00126 bool vl::isVLT(const String& path)
00127 {
00128   ref<VirtualFile> file = vl::locateFile(path);
00129   return isVLT(file.get());
00130 }
00131 //-----------------------------------------------------------------------------
00132 bool vl::isVLT(VirtualFile* file)
00133 {
00134   if (!file)
00135     return false;
00136   char vlx[12] = { 0 };
00137   memset(vlx, 0, sizeof(vlx));
00138   file->close();
00139   file->open(OM_ReadOnly);
00140   file->read(vlx, sizeof(vlx));
00141   file->close();
00142   return memcmp(vlx, "VLX version=", sizeof(vlx)) == 0;
00143 }
00144 //-----------------------------------------------------------------------------
00145 bool vl::isVLB(const String& path)
00146 {
00147   ref<VirtualFile> file = vl::locateFile(path);
00148   return isVLT(file.get());
00149 }
00150 //-----------------------------------------------------------------------------
00151 bool vl::isVLB(VirtualFile* file)
00152 {
00153   if (!file)
00154     return false;
00155   unsigned char vlx_identifier[] = { 0xAB, 'V', 'L', 'X', 0xBB, 0x0D, 0x0A, 0x1A, 0x0A };
00156   unsigned char vlx[sizeof(vlx_identifier)];
00157   memset(vlx, 0, sizeof(vlx));
00158   file->close();
00159   file->open(OM_ReadOnly);
00160   file->read(vlx, sizeof(vlx));
00161   file->close();
00162   return memcmp(vlx, vlx_identifier, sizeof(vlx_identifier)) == 0;
00163 }
00164 //-----------------------------------------------------------------------------

Visualization Library 2011.09.1160 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 2 2013 13:40:39.
Permission is granted to use this page to write and publish articles regarding Visualization Library.