summaryrefslogtreecommitdiff
path: root/indra/llcommon/llassettype.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon/llassettype.cpp')
-rw-r--r--indra/llcommon/llassettype.cpp340
1 files changed, 185 insertions, 155 deletions
diff --git a/indra/llcommon/llassettype.cpp b/indra/llcommon/llassettype.cpp
index cf3bf89b4f..b852e4c00f 100644
--- a/indra/llcommon/llassettype.cpp
+++ b/indra/llcommon/llassettype.cpp
@@ -33,145 +33,125 @@
#include "linden_common.h"
#include "llassettype.h"
+#include "lldictionary.h"
+#include "llmemory.h"
-#include "llstring.h"
-#include "lltimer.h"
+///----------------------------------------------------------------------------
+/// Class LLAssetType
+///----------------------------------------------------------------------------
+struct AssetEntry : public LLDictionaryEntry
+{
+ AssetEntry(const char *desc_name,
+ const char *type_name, // 8 character limit!
+ const char *human_name, // for decoding to human readable form; put any and as many printable characters you want in each one
+ const char *category_name, // used by llinventorymodel when creating new categories
+ EDragAndDropType dad_type,
+ bool can_link, // can you create a link to this type?
+ bool is_protected) // can the viewer change categories of this type?
+ :
+ LLDictionaryEntry(desc_name),
+ mTypeName(type_name),
+ mHumanName(human_name),
+ mCategoryName(category_name),
+ mDadType(dad_type),
+ mCanLink(can_link),
+ mIsProtected(is_protected)
+ {
+ llassert(strlen(mTypeName) <= 8);
+ }
-// I added lookups for exact text of asset type enums in addition to the ones below, so shoot me. -Steve
+ const char *mTypeName;
+ const char *mHumanName;
+ const char *mCategoryName;
+ EDragAndDropType mDadType;
+ bool mCanLink;
+ bool mIsProtected;
+};
-struct asset_info_t
+class LLAssetDictionary : public LLSingleton<LLAssetDictionary>,
+ public LLDictionary<LLAssetType::EType, AssetEntry>
{
- LLAssetType::EType type;
- const char* desc;
+public:
+ LLAssetDictionary();
};
-asset_info_t asset_types[] =
+LLAssetDictionary::LLAssetDictionary()
{
- { LLAssetType::AT_TEXTURE, "TEXTURE" },
- { LLAssetType::AT_SOUND, "SOUND" },
- { LLAssetType::AT_CALLINGCARD, "CALLINGCARD" },
- { LLAssetType::AT_LANDMARK, "LANDMARK" },
- { LLAssetType::AT_SCRIPT, "SCRIPT" },
- { LLAssetType::AT_CLOTHING, "CLOTHING" },
- { LLAssetType::AT_OBJECT, "OBJECT" },
- { LLAssetType::AT_NOTECARD, "NOTECARD" },
- { LLAssetType::AT_CATEGORY, "CATEGORY" },
- { LLAssetType::AT_ROOT_CATEGORY, "ROOT_CATEGORY" },
- { LLAssetType::AT_LSL_TEXT, "LSL_TEXT" },
- { LLAssetType::AT_LSL_BYTECODE, "LSL_BYTECODE" },
- { LLAssetType::AT_TEXTURE_TGA, "TEXTURE_TGA" },
- { LLAssetType::AT_BODYPART, "BODYPART" },
- { LLAssetType::AT_TRASH, "TRASH" },
- { LLAssetType::AT_SNAPSHOT_CATEGORY, "SNAPSHOT_CATEGORY" },
- { LLAssetType::AT_LOST_AND_FOUND, "LOST_AND_FOUND" },
- { LLAssetType::AT_SOUND_WAV, "SOUND_WAV" },
- { LLAssetType::AT_IMAGE_TGA, "IMAGE_TGA" },
- { LLAssetType::AT_IMAGE_JPEG, "IMAGE_JPEG" },
- { LLAssetType::AT_ANIMATION, "ANIMATION" },
- { LLAssetType::AT_GESTURE, "GESTURE" },
- { LLAssetType::AT_SIMSTATE, "SIMSTATE" },
- { LLAssetType::AT_NONE, "NONE" },
+ // DESCRIPTION TYPE NAME HUMAN NAME CATEGORY NAME DRAG&DROP CAN LINK? PROTECTED?
+ // |--------------------|-----------|-------------------|-------------------|---------------|-----------|-----------|
+ addEntry(LLAssetType::AT_TEXTURE, new AssetEntry("TEXTURE", "texture", "texture", "Textures", DAD_TEXTURE, FALSE, TRUE));
+ addEntry(LLAssetType::AT_SOUND, new AssetEntry("SOUND", "sound", "sound", "Sounds", DAD_SOUND, FALSE, TRUE));
+ addEntry(LLAssetType::AT_CALLINGCARD, new AssetEntry("CALLINGCARD", "callcard", "calling card", "Calling Cards", DAD_CALLINGCARD, FALSE, TRUE));
+ addEntry(LLAssetType::AT_LANDMARK, new AssetEntry("LANDMARK", "landmark", "landmark", "Landmarks", DAD_LANDMARK, FALSE, TRUE));
+ addEntry(LLAssetType::AT_SCRIPT, new AssetEntry("SCRIPT", "script", "legacy script", "Scripts", DAD_NONE, FALSE, TRUE));
+ addEntry(LLAssetType::AT_CLOTHING, new AssetEntry("CLOTHING", "clothing", "clothing", "Clothing", DAD_CLOTHING, TRUE, TRUE));
+ addEntry(LLAssetType::AT_OBJECT, new AssetEntry("OBJECT", "object", "object", "Objects", DAD_OBJECT, TRUE, TRUE));
+ addEntry(LLAssetType::AT_NOTECARD, new AssetEntry("NOTECARD", "notecard", "note card", "Notecards", DAD_NOTECARD, FALSE, TRUE));
+ addEntry(LLAssetType::AT_CATEGORY, new AssetEntry("CATEGORY", "category", "folder", "New Folder", DAD_CATEGORY, TRUE, TRUE));
+ addEntry(LLAssetType::AT_ROOT_CATEGORY, new AssetEntry("ROOT_CATEGORY", "root", "root", "Inventory", DAD_ROOT_CATEGORY, TRUE, TRUE));
+ addEntry(LLAssetType::AT_LSL_TEXT, new AssetEntry("LSL_TEXT", "lsltext", "lsl2 script", "Scripts", DAD_SCRIPT, FALSE, TRUE));
+ addEntry(LLAssetType::AT_LSL_BYTECODE, new AssetEntry("LSL_BYTECODE", "lslbyte", "lsl bytecode", "Scripts", DAD_NONE, FALSE, TRUE));
+ addEntry(LLAssetType::AT_TEXTURE_TGA, new AssetEntry("TEXTURE_TGA", "txtr_tga", "tga texture", "Uncompressed Images", DAD_NONE, FALSE, TRUE));
+ addEntry(LLAssetType::AT_BODYPART, new AssetEntry("BODYPART", "bodypart", "body part", "Body Parts", DAD_BODYPART, TRUE, TRUE));
+ addEntry(LLAssetType::AT_TRASH, new AssetEntry("TRASH", "trash", "trash", "Trash", DAD_NONE, FALSE, TRUE));
+ addEntry(LLAssetType::AT_SNAPSHOT_CATEGORY, new AssetEntry("SNAPSHOT_CATEGORY", "snapshot", "snapshot", "Photo Album", DAD_NONE, FALSE, TRUE));
+ addEntry(LLAssetType::AT_LOST_AND_FOUND, new AssetEntry("LOST_AND_FOUND", "lstndfnd", "lost and found", "Lost And Found", DAD_NONE, FALSE, TRUE));
+ addEntry(LLAssetType::AT_SOUND_WAV, new AssetEntry("SOUND_WAV", "snd_wav", "sound", "Uncompressed SoundS", DAD_NONE, FALSE, TRUE));
+ addEntry(LLAssetType::AT_IMAGE_TGA, new AssetEntry("IMAGE_TGA", "img_tga", "targa image", "Uncompressed Images", DAD_NONE, FALSE, TRUE));
+ addEntry(LLAssetType::AT_IMAGE_JPEG, new AssetEntry("IMAGE_JPEG", "jpeg", "jpeg image", "Uncompressed Images", DAD_NONE, FALSE, TRUE));
+ addEntry(LLAssetType::AT_ANIMATION, new AssetEntry("ANIMATION", "animatn", "animation", "Animations", DAD_ANIMATION, FALSE, TRUE));
+ addEntry(LLAssetType::AT_GESTURE, new AssetEntry("GESTURE", "gesture", "gesture", "Gestures", DAD_GESTURE, FALSE, TRUE));
+ addEntry(LLAssetType::AT_SIMSTATE, new AssetEntry("SIMSTATE", "simstate", "simstate", "New Folder", DAD_NONE, FALSE, TRUE));
+ addEntry(LLAssetType::AT_FAVORITE, new AssetEntry("FAVORITE", "favorite", "favorite", "favorite", DAD_NONE, FALSE, TRUE));
+
+ addEntry(LLAssetType::AT_LINK, new AssetEntry("LINK", "link", "symbolic link", "Link", DAD_LINK, FALSE, TRUE));
+ addEntry(LLAssetType::AT_LINK_FOLDER, new AssetEntry("FOLDER_LINK", "link_f", "symbolic folder link", "New Folder", DAD_LINK, FALSE, TRUE));
+
+ for (S32 ensemble_num = S32(LLAssetType::AT_FOLDER_ENSEMBLE_START);
+ ensemble_num <= S32(LLAssetType::AT_FOLDER_ENSEMBLE_END);
+ ensemble_num++)
+ {
+ addEntry(LLAssetType::EType(ensemble_num), new AssetEntry("ENSEMBLE", "ensemble", "ensemble", "New Folder", DAD_CATEGORY, TRUE, FALSE));
+ }
+
+ addEntry(LLAssetType::AT_CURRENT_OUTFIT, new AssetEntry("CURRENT", "current", "current outfit", "Current Outfit", DAD_CATEGORY, FALSE, TRUE));
+ addEntry(LLAssetType::AT_OUTFIT, new AssetEntry("OUTFIT", "outfit", "outfit", "Outfit", DAD_CATEGORY, TRUE, FALSE));
+ addEntry(LLAssetType::AT_MY_OUTFITS, new AssetEntry("MY_OUTFITS", "my_otfts", "my outfits", "My Outfits", DAD_CATEGORY, FALSE, TRUE));
+
+ addEntry(LLAssetType::AT_NONE, new AssetEntry("NONE", "-1", NULL, "New Folder", DAD_NONE, FALSE, FALSE));
};
-LLAssetType::EType LLAssetType::getType(const std::string& sin)
+// static
+LLAssetType::EType LLAssetType::getType(const std::string& desc_name)
{
- std::string s = sin;
+ std::string s = desc_name;
LLStringUtil::toUpper(s);
- for (S32 idx = 0; ;idx++)
- {
- asset_info_t* info = asset_types + idx;
- if (info->type == LLAssetType::AT_NONE)
- break;
- if (s == info->desc)
- return info->type;
- }
- return LLAssetType::AT_NONE;
+ return LLAssetDictionary::getInstance()->lookup(s);
}
-std::string LLAssetType::getDesc(LLAssetType::EType type)
+// static
+const std::string &LLAssetType::getDesc(LLAssetType::EType asset_type)
{
- for (S32 idx = 0; ;idx++)
+ const AssetEntry *entry = LLAssetDictionary::getInstance()->lookup(asset_type);
+ if (entry)
+ {
+ return entry->mName;
+ }
+ else
{
- asset_info_t* info = asset_types + idx;
- if (type == info->type)
- return info->desc;
- if (info->type == LLAssetType::AT_NONE)
- break;
+ static const std::string error_string = "BAD TYPE";
+ return error_string;
}
- return "BAD TYPE";
}
-//============================================================================
-
-// The asset type names are limited to 8 characters.
-// static
-const char* LLAssetType::mAssetTypeNames[LLAssetType::AT_COUNT] =
-{
- "texture",
- "sound",
- "callcard",
- "landmark",
- "script",
- "clothing",
- "object",
- "notecard",
- "category",
- "root",
- "lsltext",
- "lslbyte",
- "txtr_tga",// Intentionally spelled this way. Limited to eight characters.
- "bodypart",
- "trash",
- "snapshot",
- "lstndfnd",
- "snd_wav",
- "img_tga",
- "jpeg",
- "animatn",
- "gesture",
- "simstate"
-};
-
-// This table is meant for decoding to human readable form. Put any
-// and as many printable characters you want in each one.
-// See also llinventory.cpp INVENTORY_TYPE_HUMAN_NAMES
-const char* LLAssetType::mAssetTypeHumanNames[LLAssetType::AT_COUNT] =
-{
- "texture",
- "sound",
- "calling card",
- "landmark",
- "legacy script",
- "clothing",
- "object",
- "note card",
- "folder",
- "root",
- "lsl2 script",
- "lsl bytecode",
- "tga texture",
- "body part",
- "trash",
- "snapshot",
- "lost and found",
- "sound",
- "targa image",
- "jpeg image",
- "animation",
- "gesture",
- "simstate"
-};
-
-///----------------------------------------------------------------------------
-/// class LLAssetType
-///----------------------------------------------------------------------------
-
// static
-const char* LLAssetType::lookup( LLAssetType::EType type )
+const char *LLAssetType::lookup(LLAssetType::EType asset_type)
{
- if( (type >= 0) && (type < AT_COUNT ))
+ const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
+ const AssetEntry *entry = dict->lookup(asset_type);
+ if (entry)
{
- return mAssetTypeNames[ S32( type ) ];
+ return entry->mTypeName;
}
else
{
@@ -180,30 +160,35 @@ const char* LLAssetType::lookup( LLAssetType::EType type )
}
// static
-LLAssetType::EType LLAssetType::lookup( const char* name )
+LLAssetType::EType LLAssetType::lookup(const char* name)
{
return lookup(ll_safe_string(name));
}
-LLAssetType::EType LLAssetType::lookup( const std::string& name )
+LLAssetType::EType LLAssetType::lookup(const std::string& type_name)
{
- for( S32 i = 0; i < AT_COUNT; i++ )
+ const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
+ for (LLAssetDictionary::const_iterator iter = dict->begin();
+ iter != dict->end();
+ iter++)
{
- if( name == mAssetTypeNames[i] )
+ const AssetEntry *entry = iter->second;
+ if (type_name == entry->mTypeName)
{
- // match
- return (EType)i;
+ return iter->first;
}
}
return AT_NONE;
}
// static
-const char* LLAssetType::lookupHumanReadable(LLAssetType::EType type)
+const char *LLAssetType::lookupHumanReadable(LLAssetType::EType asset_type)
{
- if( (type >= 0) && (type < AT_COUNT ))
+ const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
+ const AssetEntry *entry = dict->lookup(asset_type);
+ if (entry)
{
- return mAssetTypeHumanNames[S32(type)];
+ return entry->mHumanName;
}
else
{
@@ -212,49 +197,94 @@ const char* LLAssetType::lookupHumanReadable(LLAssetType::EType type)
}
// static
-LLAssetType::EType LLAssetType::lookupHumanReadable( const char* name )
+LLAssetType::EType LLAssetType::lookupHumanReadable(const char* name)
{
return lookupHumanReadable(ll_safe_string(name));
}
-LLAssetType::EType LLAssetType::lookupHumanReadable( const std::string& name )
+LLAssetType::EType LLAssetType::lookupHumanReadable(const std::string& readable_name)
{
- for( S32 i = 0; i < AT_COUNT; i++ )
+ const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
+ for (LLAssetDictionary::const_iterator iter = dict->begin();
+ iter != dict->end();
+ iter++)
{
- if( name == mAssetTypeHumanNames[i] )
+ const AssetEntry *entry = iter->second;
+ if (readable_name == entry->mHumanName)
{
- // match
- return (EType)i;
+ return iter->first;
}
}
return AT_NONE;
}
-EDragAndDropType LLAssetType::lookupDragAndDropType( EType asset )
+// static
+const char *LLAssetType::lookupCategoryName(LLAssetType::EType asset_type)
+{
+ const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
+ const AssetEntry *entry = dict->lookup(asset_type);
+ if (entry)
+ {
+ return entry->mCategoryName;
+ }
+ else
+ {
+ return "New Folder";
+ }
+}
+
+// static
+EDragAndDropType LLAssetType::lookupDragAndDropType(EType asset_type)
+{
+ const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
+ const AssetEntry *entry = dict->lookup(asset_type);
+ if (entry)
+ return entry->mDadType;
+ else
+ return DAD_NONE;
+}
+
+// static
+bool LLAssetType::lookupCanLink(EType asset_type)
+{
+ const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
+ const AssetEntry *entry = dict->lookup(asset_type);
+ if (entry)
+ {
+ return entry->mCanLink;
+ }
+ return false;
+}
+
+// static
+// Not adding this to dictionary since we probably will only have these two types
+bool LLAssetType::lookupIsLinkType(EType asset_type)
+{
+ if (asset_type == AT_LINK || asset_type == AT_LINK_FOLDER)
+ {
+ return true;
+ }
+ return false;
+}
+
+// static
+// Only ensembles and plain folders aren't protected. "Protected" means
+// you can't change certain properties such as their type.
+bool LLAssetType::lookupIsProtectedCategoryType(EType asset_type)
{
- switch( asset )
+ const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
+ const AssetEntry *entry = dict->lookup(asset_type);
+ if (entry)
{
- case AT_TEXTURE: return DAD_TEXTURE;
- case AT_SOUND: return DAD_SOUND;
- case AT_CALLINGCARD: return DAD_CALLINGCARD;
- case AT_LANDMARK: return DAD_LANDMARK;
- case AT_SCRIPT: return DAD_NONE;
- case AT_CLOTHING: return DAD_CLOTHING;
- case AT_OBJECT: return DAD_OBJECT;
- case AT_NOTECARD: return DAD_NOTECARD;
- case AT_CATEGORY: return DAD_CATEGORY;
- case AT_ROOT_CATEGORY: return DAD_ROOT_CATEGORY;
- case AT_LSL_TEXT: return DAD_SCRIPT;
- case AT_BODYPART: return DAD_BODYPART;
- case AT_ANIMATION: return DAD_ANIMATION;
- case AT_GESTURE: return DAD_GESTURE;
- default: return DAD_NONE;
- };
+ return entry->mIsProtected;
+ }
+ return true;
}
+
// static. Generate a good default description
-void LLAssetType::generateDescriptionFor(LLAssetType::EType type,
- std::string& desc)
+void LLAssetType::generateDescriptionFor(LLAssetType::EType asset_type,
+ std::string& description)
{
const S32 BUF_SIZE = 30;
char time_str[BUF_SIZE]; /* Flawfinder: ignore */
@@ -262,6 +292,6 @@ void LLAssetType::generateDescriptionFor(LLAssetType::EType type,
time(&now);
memset(time_str, '\0', BUF_SIZE);
strftime(time_str, BUF_SIZE - 1, "%Y-%m-%d %H:%M:%S ", localtime(&now));
- desc.assign(time_str);
- desc.append(LLAssetType::lookupHumanReadable(type));
+ description.assign(time_str);
+ description.append(LLAssetType::lookupHumanReadable(asset_type));
}