Torque3D Documentation / _generateds / assetTagsManifest.h

assetTagsManifest.h

Engine/source/assets/assetTagsManifest.h

More...

Classes:

Public Defines

Detailed Description

Public Defines

ASSETTAGS_ASSETS_ASSETID_FIELD() "AssetId"
ASSETTAGS_ASSETS_NODE_NAME() "Assets"
ASSETTAGS_ASSETS_TAG_FIELD() "Name"
ASSETTAGS_ASSETS_TYPE_NAME() "Tag"
ASSETTAGS_TAGS_NAME_FIELD() "Name"
ASSETTAGS_TAGS_NODE_NAME() "Tags"
ASSETTAGS_TAGS_TYPE_NAME() "Tag"
  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2013 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _ASSET_TAGS_MANIFEST_H_
 25#define _ASSET_TAGS_MANIFEST_H_
 26
 27#ifndef _SIMBASE_H_
 28#include "console/simBase.h"
 29#endif
 30
 31#ifndef _TDICTIONARY_H_
 32#include "core/util/tDictionary.h"
 33#endif
 34
 35#ifndef _TVECTOR_H_
 36#include "core/util/tvector.h"
 37#endif
 38
 39#ifndef _STRINGUNIT_H_
 40#include "core/strings/stringUnit.h"
 41#endif
 42
 43//-----------------------------------------------------------------------------
 44
 45#define ASSETTAGS_TAGS_NODE_NAME                "Tags"
 46#define ASSETTAGS_TAGS_TYPE_NAME                "Tag"
 47#define ASSETTAGS_TAGS_NAME_FIELD               "Name"
 48
 49#define ASSETTAGS_ASSETS_NODE_NAME              "Assets"
 50#define ASSETTAGS_ASSETS_TYPE_NAME              "Tag"
 51#define ASSETTAGS_ASSETS_ASSETID_FIELD          "AssetId"
 52#define ASSETTAGS_ASSETS_TAG_FIELD              "Name"
 53
 54//-----------------------------------------------------------------------------
 55
 56class AssetManager;
 57
 58//-----------------------------------------------------------------------------
 59
 60class AssetTagsManifest : public SimObject
 61{
 62    friend class AssetManager;
 63
 64private:
 65    typedef SimObject Parent;
 66    typedef StringTableEntry typeAssetId;
 67    typedef StringTableEntry typeAssetTagName;
 68
 69public:
 70    /// Asset location.
 71    class AssetTag
 72    {
 73    public:
 74        AssetTag( StringTableEntry tagName )
 75        {
 76            // Sanity!
 77            AssertFatal( tagName != NULL, "Cannot use a NULL tag name." );
 78
 79            // Case sensitive tag name.
 80            mTagName = tagName;
 81        }
 82
 83        bool containsAsset( typeAssetId assetId )
 84        {
 85            for ( Vector<typeAssetId>::iterator assetIdItr = mAssets.begin(); assetIdItr != mAssets.end(); ++assetIdItr )
 86            {
 87                if ( *assetIdItr == assetId )
 88                    return true;
 89            }
 90
 91            return false;
 92        }
 93
 94        void removeAsset( typeAssetId assetId )
 95        {
 96            for ( Vector<typeAssetId>::iterator assetIdItr = mAssets.begin(); assetIdItr != mAssets.end(); ++assetIdItr )
 97            {
 98                if ( *assetIdItr == assetId )
 99                {
100                    mAssets.erase( assetIdItr );
101                    return;
102                }
103            }
104        }
105
106        typeAssetTagName mTagName;
107        Vector<typeAssetId> mAssets;
108    };
109
110    /// Asset/Tag database.
111    typedef HashMap<typeAssetTagName, AssetTag*> typeTagNameHash;
112    typedef HashTable<typeAssetId, AssetTag*> typeAssetToTagHash;
113
114private:
115    typeTagNameHash mTagNameDatabase;
116    typeAssetToTagHash mAssetToTagDatabase;
117
118private:
119    StringTableEntry fetchTagName( const char* pTagName );
120    AssetTag* findAssetTag( const char* pTagName );
121    void renameAssetId( const char* pAssetIdFrom, const char* pAssetIdTo );
122
123protected:
124    virtual void onTamlCustomWrite( TamlCustomNodes& customNodes );
125    virtual void onTamlCustomRead( const TamlCustomNodes& customNodes );
126
127public:
128    AssetTagsManifest();
129    virtual ~AssetTagsManifest();
130
131    /// Tagging.
132    const AssetTag* createTag( const char* pTagName );
133    bool renameTag( const char* pOldTagName, const char* pNewTagName );
134    bool deleteTag( const char* pTagName );
135    bool isTag( const char* pTagName );
136    inline U32 getTagCount( void ) const { return (U32)mTagNameDatabase.size(); }
137    StringTableEntry getTag( const U32 tagIndex );
138    U32 getAssetTagCount( const char* pAssetId );
139    StringTableEntry getAssetTag( const char* pAssetId, const U32 tagIndex );
140    bool tag( const char* pAssetId, const char* pTagName );
141    bool untag( const char* pAssetId, const char* pTagName );
142    bool hasTag( const char* pAssetId, const char* pTagName );
143
144    /// Declare Console Object.
145    DECLARE_CONOBJECT( AssetTagsManifest );
146};
147
148#endif // _ASSET_TAGS_MANIFEST_H_
149
150