resource_manager.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 */
00028 
00031 
00032 #pragma once
00033 
00034 #include "../api_core.h"
00035 #include "../Resources/resource.h"
00036 #include "../System/weakptr.h"
00037 #include "../IOData/virtual_directory.h"
00038 #include <vector>
00039 
00040 class CL_IODevice;
00041 class CL_Resource;
00042 class CL_VirtualDirectory;
00043 class CL_ResourceManager_Impl;
00044 
00048 class CL_API_CORE CL_ResourceManager
00049 {
00052 public:
00054         CL_ResourceManager();
00055 
00059         CL_ResourceManager(const CL_String &filename);
00060 
00065         CL_ResourceManager(const CL_String &filename, CL_VirtualDirectory directory);
00066 
00071         CL_ResourceManager(CL_IODevice file, CL_VirtualDirectory directory = CL_VirtualDirectory());
00072 
00076         CL_ResourceManager(const CL_ResourceManager &other);
00077 
00078         ~CL_ResourceManager();
00079 
00083 public:
00085         bool resource_exists(const CL_String &resource_id) const;
00086 
00088         std::vector<CL_String> get_section_names() const;
00089 
00091 
00092         std::vector<CL_String> get_resource_names() const;
00093 
00094         std::vector<CL_String> get_resource_names(const CL_String &section) const;
00095 
00097 
00098         std::vector<CL_String> get_resource_names_of_type(const CL_String &type) const;
00099 
00100         std::vector<CL_String> get_resource_names_of_type(
00101                 const CL_String &type,
00102                 const CL_String &section) const;
00103 
00105         CL_Resource get_resource(
00106                 const CL_String &resource_id,
00107                 bool resolve_alias = true,
00108                 int reserved = 0);
00109 
00111         CL_VirtualDirectory get_directory(const CL_Resource &resource) const;
00112 
00114         bool get_boolean_resource(
00115                 const CL_String &resource_id,
00116                 bool default_value);
00117 
00119         int get_integer_resource(
00120                 const CL_String &resource_id,
00121                 int default_value);
00122 
00124         CL_String get_string_resource(
00125                 const CL_String &resource_id,
00126                 const CL_StringRef &default_value);
00127 
00131 public:
00132         CL_ResourceManager &operator =(const CL_ResourceManager &copy);
00133 
00134         bool operator ==(const CL_ResourceManager &manager) const;
00135 
00137         void set_directory(const CL_VirtualDirectory &directory);
00138 
00140 
00142         void add_resources(const CL_ResourceManager& additional_resources);
00143 
00145         void remove_resources(const CL_ResourceManager& additional_resources);
00146 
00148         CL_Resource create_resource(const CL_String &resource_id, const CL_String &type);
00149 
00151         void destroy_resource(const CL_String &resource_id);
00152 
00154         void save(const CL_String &filename);
00155 
00160         void save(const CL_String &filename, CL_VirtualDirectory directory);
00161 
00165         void save(CL_IODevice file);
00166 
00168         void load(const CL_String &filename);
00169 
00174         void load(const CL_String &filename, CL_VirtualDirectory directory);
00175 
00180         void load(CL_IODevice file, CL_VirtualDirectory directory = CL_VirtualDirectory());
00181 
00185 private:
00186 
00190         CL_ResourceManager(CL_WeakPtr<CL_ResourceManager_Impl> &impl);
00191 
00192         CL_SharedPtr<CL_ResourceManager_Impl> impl;
00193 
00194         friend class CL_Resource;
00196 };
00197