# Visualization Library

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

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

- Main Page
- Related Pages
- 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.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 #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/MemoryFile.hpp>
    00039 #include <vlCore/VisualizationLibrary.hpp>
    00040
    00041 namespace vl
    00042 {
    00044   class LoadCallback: public Object
    00045   {
    00046   public:
    00047     virtual void operator()(ResourceDatabase* db) = 0;
    00048   };
    00049
    00051   class WriteCallback: public Object
    00052   {
    00053   public:
    00054     virtual void operator()(ResourceDatabase* db) = 0;
    00055   };
    00056
    00060   class VLCORE_EXPORT LoadWriterManager: public Object
    00061   {
    00062     VL_INSTRUMENT_CLASS(vl::LoadWriterManager, Object)
    00063
    00064   public:
    00065     LoadWriterManager()
    00066     {
    00067       VL_DEBUG_SET_OBJECT_NAME()
    00068     }
    00069
    00070     void registerLoadWriter(ResourceLoadWriter*);
    00071
    00073     std::vector< ref<ResourceLoadWriter> >& loadWriters() { return mLoadWriters; }
    00074
    00076     const std::vector< ref<ResourceLoadWriter> >& loadWriters() const { return mLoadWriters; }
    00077
    00079     template<class T>
    00080     T* loadWriter()
    00081     {
    00082       for(size_t i=0; i<loadWriters().size(); ++i)
    00083       {
    00084         T* load_writer = loadWriters()[i]->as<T>();
    00085         if (load_writer)
    00086           return load_writer;
    00087       }
    00088       return NULL;
    00089     }
    00090
    00092     bool canLoad(const String& path)  const { return findLoader(path) != NULL; }
    00093
    00095     bool canLoad(VirtualFile* file)   const { return findLoader(file->path()) != NULL; }
    00096
    00098     bool canWrite(const String& path) const { return findWriter(path) != NULL; }
    00099
    00101     bool canWrite(VirtualFile* file)  const { return findWriter(file->path()) != NULL; }
    00102
    00104     const ResourceLoadWriter* findLoader(const String& path) const;
    00105
    00107     const ResourceLoadWriter* findWriter(const String& path) const;
    00108
    00110     const ResourceLoadWriter* findLoader(VirtualFile* file) const;
    00111
    00113     const ResourceLoadWriter* findWriter(VirtualFile* file) const;
    00114
    00116     ref<ResourceDatabase> loadResource(const String& path, bool quick=true) const;
    00117
    00119     ref<ResourceDatabase> loadResource(VirtualFile* file, bool quick=true) const;
    00120
    00122     bool writeResource(const String& path, ResourceDatabase* resource) const;
    00123
    00125     bool writeResource(VirtualFile* file, ResourceDatabase* resource) const;
    00126
    00127     const std::vector< ref<LoadCallback> >& loadCallbacks() const { return mLoadCallbacks; }
    00128
    00129     const std::vector< ref<WriteCallback> >& writeCallbacks() const { return mWriteCallbacks; }
    00130
    00131     std::vector< ref<LoadCallback> >& loadCallbacks() { return mLoadCallbacks; }
    00132
    00133     std::vector< ref<WriteCallback> >& writeCallbacks() { return mWriteCallbacks; }
    00134
    00135   protected:
    00136     std::vector< ref<ResourceLoadWriter> > mLoadWriters;
    00137     std::vector< ref<LoadCallback> > mLoadCallbacks;
    00138     std::vector< ref<WriteCallback> > mWriteCallbacks;
    00139   };
    00140
    00142   VLCORE_EXPORT LoadWriterManager* defLoadWriterManager();
    00143
    00145   VLCORE_EXPORT void setDefLoadWriterManager(LoadWriterManager* lwm);
    00146
    00148   inline void registerLoadWriter(ResourceLoadWriter* rlw) { defLoadWriterManager()->registerLoadWriter(rlw); }
    00149 }
    00150
    00151 #endif

Visualization Library v2011.09.1162 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu Jan 26 2012 00:43:28.
Permission is granted to use this page to write and publish articles regarding Visualization Library.