# 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/ResourceDatabase.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 ResourceDatabase_INCLUDE_ONCE
    00033 #define ResourceDatabase_INCLUDE_ONCE
    00034
    00035 #include <vlCore/Object.hpp>
    00036 #include <vlCore/String.hpp>
    00037 #include <vector>
    00038 #include <algorithm>
    00039
    00040 namespace vl
    00041 {
    00042   class VirtualFile;
    00043
    00048   class ResourceDatabase: public Object
    00049   {
    00050   public:
    00051     virtual const char* className() { return "vl::ResourceDatabase"; }
    00052
    00053     const std::vector< ref<Object> >& resources() const { return mResources; }
    00054
    00055     std::vector< ref<Object> >& resources() { return mResources; }
    00056
    00058     template<class T>
    00059     T* next(int& cur_pos) const
    00060     {
    00061       for(unsigned i=cur_pos; i<mResources.size(); ++i)
    00062       {
    00063         ref<T> r = dynamic_cast<T*>(mResources[i].get());
    00064         if (r)
    00065         {
    00066           cur_pos = i+1;
    00067           return r.get();
    00068         }
    00069       }
    00070       return NULL;
    00071     }
    00072
    00074     template<class T>
    00075     void get( std::vector< ref<T> >& resources, bool clear_vector=true )
    00076     {
    00077       if (clear_vector)
    00078         resources.clear();
    00079
    00080       for( unsigned i=0; i<mResources.size(); ++i )
    00081       {
    00082         ref<T> r = dynamic_cast<T*>(mResources[i].get());
    00083         if (r)
    00084           resources.push_back(r);
    00085       }
    00086     }
    00087
    00089     template<class T>
    00090     void extract( std::vector< ref<T> >& resources, bool clear_vector=true )
    00091     {
    00092       if (clear_vector)
    00093         resources.clear();
    00094
    00095       size_t start = resources.size();
    00096
    00097       for( unsigned i=mResources.size(); i--; )
    00098       {
    00099         ref<T> r = dynamic_cast<T*>(mResources[i].get());
    00100         if (r)
    00101         {
    00102           resources.push_back(r);
    00103           mResources.erase(mResources.begin()+i);
    00104         }
    00105       }
    00106
    00107       std::reverse(resources.begin()+start, resources.end());
    00108     }
    00109
    00111     template<class T>
    00112     size_t count() const
    00113     {
    00114       size_t count=0;
    00115       for(unsigned i=0; i<mResources.size(); ++i)
    00116       {
    00117         ref<T> r = dynamic_cast<T*>(mResources[i].get());
    00118         if (r)
    00119           ++count;
    00120       }
    00121       return count;
    00122     }
    00123
    00125     template<class T>
    00126     T* get(int j) const
    00127     {
    00128       int count=0;
    00129       for(unsigned i=0; i<mResources.size(); ++i)
    00130       {
    00131         ref<T> r = dynamic_cast<T*>(mResources[i].get());
    00132         if (r)
    00133         {
    00134           if (count == j)
    00135             return r.get();
    00136           else
    00137             ++count;
    00138         }
    00139       }
    00140       return NULL;
    00141     }
    00142
    00143   protected:
    00144     std::vector< ref<Object> > mResources;
    00145   };
    00146
    00148   VLCORE_EXPORT bool canLoad(const String& path);
    00149
    00151   VLCORE_EXPORT bool canWrite(const String& path);
    00152
    00154   VLCORE_EXPORT bool canLoad(VirtualFile* file);
    00155
    00157   VLCORE_EXPORT bool canWrite(VirtualFile* file);
    00158
    00160   VLCORE_EXPORT ref<ResourceDatabase> loadResource(const String& path, bool quick=true);
    00161
    00163   VLCORE_EXPORT ref<ResourceDatabase> loadResource(VirtualFile* file, bool quick=true);
    00164 }
    00165
    00166 #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.