Spinning Topp Logo BlackTopp Studios
inc
assetgroup.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _resourceassetgroup_h
41 #define _resourceassetgroup_h
42 
43 #include "Resource/datastream.h"
44 
45 namespace Mezzanine
46 {
47  namespace Resource
48  {
49  ///////////////////////////////////////////////////////////////////////////////
50  /// @brief This is a class that stores a specific grouping of Assets, usually based on thier location.
51  /// @details
52  ///////////////////////////////////////
53  class AssetGroup
54  {
55  public:
56  /// @brief Basic container type for @ref DataStream storage by this class.
57  typedef std::vector<Resource::DataStreamPtr> UnnamedAssetContainer;
58  /// @brief Iterator type for @ref DataStream instances stored by this class.
59  typedef UnnamedAssetContainer::iterator UnnamedAssetIterator;
60  /// @brief Const Iterator type for @ref DataStream instances stored by this class.
61  typedef UnnamedAssetContainer::const_iterator ConstUnnamedAssetIterator;
62  /// @brief Container class for storing @ref DataStream instances in this class.
63  typedef std::map<String,DataStreamPtr> AssetContainer;
64  /// @brief Iterator type for @ref DataStream instances stored in this class.
65  typedef AssetContainer::iterator AssetIterator;
66  /// @brief Const Iterator type for @ref DataStream instances stored in this class.
67  typedef AssetContainer::const_iterator ConstAssetIterator;
68  protected:
69  /// @internal
70  /// @brief Container storing all of the unnamed open streams bleonging to this group.
71  UnnamedAssetContainer UnnamedGroupAssets;
72  /// @internal
73  /// @brief Container storing all of the named open streams belonging to this group.
74  AssetContainer GroupAssets;
75  /// @internal
76  /// @brief The name of this group.
78  public:
79  /// @brief Class constructor.
80  /// @param GroupName The name to be given to this group.
81  AssetGroup(const String& GroupName);
82  /// @brief Class destructor.
83  ~AssetGroup();
84 
85  ///////////////////////////////////////////////////////////////////////////////
86  // Utility
87 
88  /// @brief Gets the name of this asset group.
89  /// @return Returns a const reference to a string containing the name of this group.
90  const String& GetName() const;
91 
92  /// @brief Prepares some Assets for use within this group.
93  /// @details After adding all of your assets and declaring them as nessessary, this function
94  /// is the final step. After calling this function any and all assets within the defined group
95  /// will be ready to use. Do not initialize any more groups then you need to however, as that will
96  /// take up memory and drop performance.
97  void InitializeAssets();
98 
99  ///////////////////////////////////////////////////////////////////////////////
100  // Stream Management
101 
102  /// @brief Opens a stream to an asset in an AssetGroup.
103  /// @param AssetName The identity of the asset to be opened (commonly a file name).
105 
106  /// @brief Creates a stream from a memory buffer.
107  /// @note The created stream will take ownership of the buffer you provide. If you want it to have a separate buffer then create a copy and pass that in.
108  /// @param Buffer A pointer to the memory to stream from.
109  /// @param BufferSize The size of the provided buffer in bytes.
110  /// @return Returns a @ref CountedPtr to the stream to the provided buffer.
111  Resource::DataStreamPtr CreateDataStream(void* Buffer, const UInt32 BufferSize);
112  /// @brief Creates a named stream from a memory buffer.
113  /// @note The created stream will take ownership of the buffer you provide. If you want it to have a separate buffer then create a copy and pass that in.
114  /// @param AssetName The name to be given to the created stream.
115  /// @param Buffer A pointer to the memory to stream from.
116  /// @param BufferSize The size of the provided buffer in bytes.
117  /// @return Returns a @ref CountedPtr to the stream to the provided buffer.
118  Resource::DataStreamPtr CreateDataStream(const String& AssetName, void* Buffer, const UInt32 BufferSize);
119  };//AssetGroup
120  }//Resource
121 }//Mezzanine
122 
123 #endif
UnnamedAssetContainer UnnamedGroupAssets
Container storing all of the unnamed open streams bleonging to this group.
Definition: assetgroup.h:71
UnnamedAssetContainer::iterator UnnamedAssetIterator
Iterator type for DataStream instances stored by this class.
Definition: assetgroup.h:59
String Name
The name of this group.
Definition: assetgroup.h:77
std::vector< Resource::DataStreamPtr > UnnamedAssetContainer
Basic container type for DataStream storage by this class.
Definition: assetgroup.h:57
A simple reference counting pointer.
Definition: countedptr.h:70
UnnamedAssetContainer::const_iterator ConstUnnamedAssetIterator
Const Iterator type for DataStream instances stored by this class.
Definition: assetgroup.h:61
const String & GetName() const
Gets the name of this asset group.
Definition: assetgroup.cpp:67
AssetGroup(const String &GroupName)
Class constructor.
Definition: assetgroup.cpp:53
~AssetGroup()
Class destructor.
Definition: assetgroup.cpp:59
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
AssetContainer GroupAssets
Container storing all of the named open streams belonging to this group.
Definition: assetgroup.h:74
This is a class that stores a specific grouping of Assets, usually based on thier location...
Definition: assetgroup.h:53
Resource::DataStreamPtr CreateDataStream(void *Buffer, const UInt32 BufferSize)
Creates a stream from a memory buffer.
Definition: assetgroup.cpp:97
void InitializeAssets()
Prepares some Assets for use within this group.
Definition: assetgroup.cpp:72
AssetContainer::const_iterator ConstAssetIterator
Const Iterator type for DataStream instances stored in this class.
Definition: assetgroup.h:67
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
AssetContainer::iterator AssetIterator
Iterator type for DataStream instances stored in this class.
Definition: assetgroup.h:65
Resource::DataStreamPtr OpenAssetStream(const String &AssetName)
Opens a stream to an asset in an AssetGroup.
Definition: assetgroup.cpp:80
std::map< String, DataStreamPtr > AssetContainer
Container class for storing DataStream instances in this class.
Definition: assetgroup.h:63
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
Declaration of DataStream.