# Visualization Library

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

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlCore/LoadWriterManager.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.com                                               */
    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 #ifndef LoadWriterManager_INCLUDE_ONCE
    00033 #define LoadWriterManager_INCLUDE_ONCE
    00034
    00035 #include <vlCore/ResourceLoadWriter.hpp>
    00036 #include <vlCore/ResourceDatabase.hpp>
    00037 #include <vlCore/VirtualFile.hpp>
    00038 #include <vlCore/Collection.hpp>
    00039 #include <vlCore/MemoryFile.hpp>
    00040 #include <vlCore/VisualizationLibrary.hpp>
    00041
    00042 namespace vl
    00043 {
    00045   class LoadCallback: public Object
    00046   {
    00047   public:
    00048     virtual void operator()(ResourceDatabase* db) = 0;
    00049   };
    00050
    00052   class WriteCallback: public Object
    00053   {
    00054   public:
    00055     virtual void operator()(ResourceDatabase* db) = 0;
    00056   };
    00057
    00061   class VLCORE_EXPORT LoadWriterManager: public Object
    00062   {
    00063   public:
    00064     virtual const char* className() { return "vl::LoadWriterManager"; }
    00065
    00066     LoadWriterManager()
    00067     {
    00068       mLoadWriters.setAutomaticDelete(false);
    00069       mLoadCallbacks.setAutomaticDelete(false);
    00070       mWriteCallbacks.setAutomaticDelete(false);
    00071     }
    00072
    00073     LoadWriterManager(const LoadWriterManager& other): Object(other)
    00074     {
    00075       mLoadWriters.setAutomaticDelete(false);
    00076       mLoadCallbacks.setAutomaticDelete(false);
    00077       mWriteCallbacks.setAutomaticDelete(false);
    00078     }
    00079
    00080     void registerLoadWriter(ResourceLoadWriter*);
    00081
    00083     Collection<ResourceLoadWriter>* loadWriters() { return &mLoadWriters; }
    00084
    00086     const Collection<ResourceLoadWriter>* loadWriters() const { return &mLoadWriters; }
    00087
    00089     template<class T>
    00090     T* loadWriter()
    00091     {
    00092       for(int i=0; i<loadWriters()->size(); ++i)
    00093       {
    00094         T* load_writer = dynamic_cast<T*>(loadWriters()->at(i));
    00095         if (load_writer)
    00096           return load_writer;
    00097       }
    00098       return NULL;
    00099     }
    00100
    00102     bool canLoad(const String& path)  const { return findLoader(path) != NULL; }
    00103
    00105     bool canLoad(VirtualFile* file)   const { return findLoader(file->path()) != NULL; }
    00106
    00108     bool canWrite(const String& path) const { return findWriter(path) != NULL; }
    00109
    00111     bool canWrite(VirtualFile* file)  const { return findWriter(file->path()) != NULL; }
    00112
    00114     const ResourceLoadWriter* findLoader(const String& path) const;
    00115
    00117     const ResourceLoadWriter* findWriter(const String& path) const;
    00118
    00120     const ResourceLoadWriter* findLoader(VirtualFile* file) const;
    00121
    00123     const ResourceLoadWriter* findWriter(VirtualFile* file) const;
    00124
    00126     ref<ResourceDatabase> loadResource(const String& path, bool quick=true) const;
    00127
    00129     ref<ResourceDatabase> loadResource(VirtualFile* file, bool quick=true) const;
    00130
    00132     bool writeResource(const String& path, ResourceDatabase* resource) const;
    00133
    00135     bool writeResource(VirtualFile* file, ResourceDatabase* resource) const;
    00136
    00137     const Collection<LoadCallback>* loadCallbacks() const { return &mLoadCallbacks; }
    00138
    00139     const Collection<WriteCallback>* writeCallbacks() const { return &mWriteCallbacks; }
    00140
    00141     Collection<LoadCallback>* loadCallbacks() { return &mLoadCallbacks; }
    00142
    00143     Collection<WriteCallback>* writeCallbacks() { return &mWriteCallbacks; }
    00144
    00145   protected:
    00146     Collection<ResourceLoadWriter> mLoadWriters;
    00147     Collection<LoadCallback> mLoadCallbacks;
    00148     Collection<WriteCallback> mWriteCallbacks;
    00149   };
    00150
    00152   VLCORE_EXPORT LoadWriterManager* defLoadWriterManager();
    00153
    00155   VLCORE_EXPORT void setDefLoadWriterManager(LoadWriterManager* lwm);
    00156
    00158   inline void registerLoadWriter(ResourceLoadWriter* rlw) { defLoadWriterManager()->registerLoadWriter(rlw); }
    00159 }
    00160
    00161 #endif

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:21.
Permission is granted to use this page to write and publish articles regarding Visualization Library.