PageRenderTime 36ms CodeModel.GetById 11ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llcommon/llassettype.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 253 lines | 187 code | 22 blank | 44 comment | 19 complexity | 2b00bd471464e8bb0fb290bfe7b77b58 MD5 | raw file
  1/** 
  2 * @file llassettype.cpp
  3 * @brief Implementatino of LLAssetType functionality.
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "linden_common.h"
 28
 29#include "llassettype.h"
 30#include "lldictionary.h"
 31#include "llmemory.h"
 32#include "llsingleton.h"
 33
 34///----------------------------------------------------------------------------
 35/// Class LLAssetType
 36///----------------------------------------------------------------------------
 37struct AssetEntry : public LLDictionaryEntry
 38{
 39	AssetEntry(const char *desc_name,
 40			   const char *type_name, 	// 8 character limit!
 41			   const char *human_name, 	// for decoding to human readable form; put any and as many printable characters you want in each one
 42			   bool can_link, 			// can you create a link to this type?
 43			   bool can_fetch, 			// can you fetch this asset by ID?
 44			   bool can_know) 			// can you see this asset's ID?
 45		:
 46		LLDictionaryEntry(desc_name),
 47		mTypeName(type_name),
 48		mHumanName(human_name),
 49		mCanLink(can_link),
 50		mCanFetch(can_fetch),
 51		mCanKnow(can_know)
 52	{
 53		llassert(strlen(mTypeName) <= 8);
 54	}
 55
 56	const char *mTypeName;
 57	const char *mHumanName;
 58	bool mCanLink;
 59	bool mCanFetch;
 60	bool mCanKnow;
 61};
 62
 63class LLAssetDictionary : public LLSingleton<LLAssetDictionary>,
 64						  public LLDictionary<LLAssetType::EType, AssetEntry>
 65{
 66public:
 67	LLAssetDictionary();
 68};
 69
 70LLAssetDictionary::LLAssetDictionary()
 71{
 72	//       												   DESCRIPTION			TYPE NAME	HUMAN NAME			CAN LINK?   CAN FETCH?  CAN KNOW?	
 73	//      												  |--------------------|-----------|-------------------|-----------|-----------|---------|
 74	addEntry(LLAssetType::AT_TEXTURE, 			new AssetEntry("TEXTURE",			"texture",	"texture",			true,		false,		true));
 75	addEntry(LLAssetType::AT_SOUND, 			new AssetEntry("SOUND",				"sound",	"sound",			true,		true,		true));
 76	addEntry(LLAssetType::AT_CALLINGCARD, 		new AssetEntry("CALLINGCARD",		"callcard",	"calling card",		true,		false,		false));
 77	addEntry(LLAssetType::AT_LANDMARK, 			new AssetEntry("LANDMARK",			"landmark",	"landmark",			true,		true,		true));
 78	addEntry(LLAssetType::AT_SCRIPT, 			new AssetEntry("SCRIPT",			"script",	"legacy script",	true,		false,		false));
 79	addEntry(LLAssetType::AT_CLOTHING, 			new AssetEntry("CLOTHING",			"clothing",	"clothing",			true,		true,		true));
 80	addEntry(LLAssetType::AT_OBJECT, 			new AssetEntry("OBJECT",			"object",	"object",			true,		false,		false));
 81	addEntry(LLAssetType::AT_NOTECARD, 			new AssetEntry("NOTECARD",			"notecard",	"note card",		true,		false,		true));
 82	addEntry(LLAssetType::AT_CATEGORY, 			new AssetEntry("CATEGORY",			"category",	"folder",			true,		false,		false));
 83	addEntry(LLAssetType::AT_LSL_TEXT, 			new AssetEntry("LSL_TEXT",			"lsltext",	"lsl2 script",		true,		false,		false));
 84	addEntry(LLAssetType::AT_LSL_BYTECODE, 		new AssetEntry("LSL_BYTECODE",		"lslbyte",	"lsl bytecode",		true,		false,		false));
 85	addEntry(LLAssetType::AT_TEXTURE_TGA, 		new AssetEntry("TEXTURE_TGA",		"txtr_tga",	"tga texture",		true,		false,		false));
 86	addEntry(LLAssetType::AT_BODYPART, 			new AssetEntry("BODYPART",			"bodypart",	"body part",		true,		true,		true));
 87	addEntry(LLAssetType::AT_SOUND_WAV, 		new AssetEntry("SOUND_WAV",			"snd_wav",	"sound",			true,		false,		false));
 88	addEntry(LLAssetType::AT_IMAGE_TGA, 		new AssetEntry("IMAGE_TGA",			"img_tga",	"targa image",		true,		false,		false));
 89	addEntry(LLAssetType::AT_IMAGE_JPEG, 		new AssetEntry("IMAGE_JPEG",		"jpeg",		"jpeg image",		true,		false,		false));
 90	addEntry(LLAssetType::AT_ANIMATION, 		new AssetEntry("ANIMATION",			"animatn",	"animation",		true,		true,		true));
 91	addEntry(LLAssetType::AT_GESTURE, 			new AssetEntry("GESTURE",			"gesture",	"gesture",			true,		true,		true));
 92	addEntry(LLAssetType::AT_SIMSTATE, 			new AssetEntry("SIMSTATE",			"simstate",	"simstate",			false,		false,		false));
 93
 94	addEntry(LLAssetType::AT_LINK, 				new AssetEntry("LINK",				"link",		"sym link",			false,		false,		true));
 95	addEntry(LLAssetType::AT_LINK_FOLDER, 		new AssetEntry("FOLDER_LINK",		"link_f", 	"sym folder link",	false,		false,		true));
 96	addEntry(LLAssetType::AT_MESH,              new AssetEntry("MESH",              "mesh",     "mesh",             false,      false,      false));
 97	addEntry(LLAssetType::AT_WIDGET,            new AssetEntry("WIDGET",            "widget",   "widget",           false,      false,      false));
 98	addEntry(LLAssetType::AT_NONE, 				new AssetEntry("NONE",				"-1",		NULL,		  		FALSE,		FALSE,		FALSE));
 99
100};
101
102// static
103LLAssetType::EType LLAssetType::getType(const std::string& desc_name)
104{
105	std::string s = desc_name;
106	LLStringUtil::toUpper(s);
107	return LLAssetDictionary::getInstance()->lookup(s);
108}
109
110// static
111const std::string &LLAssetType::getDesc(LLAssetType::EType asset_type)
112{
113	const AssetEntry *entry = LLAssetDictionary::getInstance()->lookup(asset_type);
114	if (entry)
115	{
116		return entry->mName;
117	}
118	else
119	{
120		return badLookup();
121	}
122}
123
124// static
125const char *LLAssetType::lookup(LLAssetType::EType asset_type)
126{
127	const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
128	const AssetEntry *entry = dict->lookup(asset_type);
129	if (entry)
130	{
131		return entry->mTypeName;
132	}
133	else
134	{
135		return badLookup().c_str();
136	}
137}
138
139// static
140LLAssetType::EType LLAssetType::lookup(const char* name)
141{
142	return lookup(ll_safe_string(name));
143}
144
145// static
146LLAssetType::EType LLAssetType::lookup(const std::string& type_name)
147{
148	const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
149	for (LLAssetDictionary::const_iterator iter = dict->begin();
150		 iter != dict->end();
151		 iter++)
152	{
153		const AssetEntry *entry = iter->second;
154		if (type_name == entry->mTypeName)
155		{
156			return iter->first;
157		}
158	}
159	return AT_NONE;
160}
161
162// static
163const char *LLAssetType::lookupHumanReadable(LLAssetType::EType asset_type)
164{
165	const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
166	const AssetEntry *entry = dict->lookup(asset_type);
167	if (entry)
168	{
169		return entry->mHumanName;
170	}
171	else
172	{
173		return badLookup().c_str();
174	}
175}
176
177// static
178LLAssetType::EType LLAssetType::lookupHumanReadable(const char* name)
179{
180	return lookupHumanReadable(ll_safe_string(name));
181}
182
183// static
184LLAssetType::EType LLAssetType::lookupHumanReadable(const std::string& readable_name)
185{
186	const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
187	for (LLAssetDictionary::const_iterator iter = dict->begin();
188		 iter != dict->end();
189		 iter++)
190	{
191		const AssetEntry *entry = iter->second;
192		if (entry->mHumanName && (readable_name == entry->mHumanName))
193		{
194			return iter->first;
195		}
196	}
197	return AT_NONE;
198}
199
200// static
201bool LLAssetType::lookupCanLink(EType asset_type)
202{
203	const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
204	const AssetEntry *entry = dict->lookup(asset_type);
205	if (entry)
206	{
207		return entry->mCanLink;
208	}
209	return false;
210}
211
212// static
213// Not adding this to dictionary since we probably will only have these two types
214bool LLAssetType::lookupIsLinkType(EType asset_type)
215{
216	if (asset_type == AT_LINK || asset_type == AT_LINK_FOLDER)
217	{
218		return true;
219	}
220	return false;
221}
222
223// static
224const std::string &LLAssetType::badLookup()
225{
226	static const std::string sBadLookup = "llassettype_bad_lookup";
227	return sBadLookup;
228
229}
230
231// static
232bool LLAssetType::lookupIsAssetFetchByIDAllowed(EType asset_type)
233{
234	const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
235	const AssetEntry *entry = dict->lookup(asset_type);
236	if (entry)
237	{
238		return entry->mCanFetch;
239	}
240	return false;
241}
242
243// static
244bool LLAssetType::lookupIsAssetIDKnowable(EType asset_type)
245{
246	const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
247	const AssetEntry *entry = dict->lookup(asset_type);
248	if (entry)
249	{
250		return entry->mCanKnow;
251	}
252	return false;
253}