PageRenderTime 32ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): LGPL-2.1
  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. #include "linden_common.h"
  27. #include "llassettype.h"
  28. #include "lldictionary.h"
  29. #include "llmemory.h"
  30. #include "llsingleton.h"
  31. ///----------------------------------------------------------------------------
  32. /// Class LLAssetType
  33. ///----------------------------------------------------------------------------
  34. struct AssetEntry : public LLDictionaryEntry
  35. {
  36. AssetEntry(const char *desc_name,
  37. const char *type_name, // 8 character limit!
  38. const char *human_name, // for decoding to human readable form; put any and as many printable characters you want in each one
  39. bool can_link, // can you create a link to this type?
  40. bool can_fetch, // can you fetch this asset by ID?
  41. bool can_know) // can you see this asset's ID?
  42. :
  43. LLDictionaryEntry(desc_name),
  44. mTypeName(type_name),
  45. mHumanName(human_name),
  46. mCanLink(can_link),
  47. mCanFetch(can_fetch),
  48. mCanKnow(can_know)
  49. {
  50. llassert(strlen(mTypeName) <= 8);
  51. }
  52. const char *mTypeName;
  53. const char *mHumanName;
  54. bool mCanLink;
  55. bool mCanFetch;
  56. bool mCanKnow;
  57. };
  58. class LLAssetDictionary : public LLSingleton<LLAssetDictionary>,
  59. public LLDictionary<LLAssetType::EType, AssetEntry>
  60. {
  61. public:
  62. LLAssetDictionary();
  63. };
  64. LLAssetDictionary::LLAssetDictionary()
  65. {
  66. // DESCRIPTION TYPE NAME HUMAN NAME CAN LINK? CAN FETCH? CAN KNOW?
  67. // |--------------------|-----------|-------------------|-----------|-----------|---------|
  68. addEntry(LLAssetType::AT_TEXTURE, new AssetEntry("TEXTURE", "texture", "texture", true, false, true));
  69. addEntry(LLAssetType::AT_SOUND, new AssetEntry("SOUND", "sound", "sound", true, true, true));
  70. addEntry(LLAssetType::AT_CALLINGCARD, new AssetEntry("CALLINGCARD", "callcard", "calling card", true, false, false));
  71. addEntry(LLAssetType::AT_LANDMARK, new AssetEntry("LANDMARK", "landmark", "landmark", true, true, true));
  72. addEntry(LLAssetType::AT_SCRIPT, new AssetEntry("SCRIPT", "script", "legacy script", true, false, false));
  73. addEntry(LLAssetType::AT_CLOTHING, new AssetEntry("CLOTHING", "clothing", "clothing", true, true, true));
  74. addEntry(LLAssetType::AT_OBJECT, new AssetEntry("OBJECT", "object", "object", true, false, false));
  75. addEntry(LLAssetType::AT_NOTECARD, new AssetEntry("NOTECARD", "notecard", "note card", true, false, true));
  76. addEntry(LLAssetType::AT_CATEGORY, new AssetEntry("CATEGORY", "category", "folder", true, false, false));
  77. addEntry(LLAssetType::AT_LSL_TEXT, new AssetEntry("LSL_TEXT", "lsltext", "lsl2 script", true, false, false));
  78. addEntry(LLAssetType::AT_LSL_BYTECODE, new AssetEntry("LSL_BYTECODE", "lslbyte", "lsl bytecode", true, false, false));
  79. addEntry(LLAssetType::AT_TEXTURE_TGA, new AssetEntry("TEXTURE_TGA", "txtr_tga", "tga texture", true, false, false));
  80. addEntry(LLAssetType::AT_BODYPART, new AssetEntry("BODYPART", "bodypart", "body part", true, true, true));
  81. addEntry(LLAssetType::AT_SOUND_WAV, new AssetEntry("SOUND_WAV", "snd_wav", "sound", true, false, false));
  82. addEntry(LLAssetType::AT_IMAGE_TGA, new AssetEntry("IMAGE_TGA", "img_tga", "targa image", true, false, false));
  83. addEntry(LLAssetType::AT_IMAGE_JPEG, new AssetEntry("IMAGE_JPEG", "jpeg", "jpeg image", true, false, false));
  84. addEntry(LLAssetType::AT_ANIMATION, new AssetEntry("ANIMATION", "animatn", "animation", true, true, true));
  85. addEntry(LLAssetType::AT_GESTURE, new AssetEntry("GESTURE", "gesture", "gesture", true, true, true));
  86. addEntry(LLAssetType::AT_SIMSTATE, new AssetEntry("SIMSTATE", "simstate", "simstate", false, false, false));
  87. addEntry(LLAssetType::AT_LINK, new AssetEntry("LINK", "link", "sym link", false, false, true));
  88. addEntry(LLAssetType::AT_LINK_FOLDER, new AssetEntry("FOLDER_LINK", "link_f", "sym folder link", false, false, true));
  89. addEntry(LLAssetType::AT_MESH, new AssetEntry("MESH", "mesh", "mesh", false, false, false));
  90. addEntry(LLAssetType::AT_WIDGET, new AssetEntry("WIDGET", "widget", "widget", false, false, false));
  91. addEntry(LLAssetType::AT_NONE, new AssetEntry("NONE", "-1", NULL, FALSE, FALSE, FALSE));
  92. };
  93. // static
  94. LLAssetType::EType LLAssetType::getType(const std::string& desc_name)
  95. {
  96. std::string s = desc_name;
  97. LLStringUtil::toUpper(s);
  98. return LLAssetDictionary::getInstance()->lookup(s);
  99. }
  100. // static
  101. const std::string &LLAssetType::getDesc(LLAssetType::EType asset_type)
  102. {
  103. const AssetEntry *entry = LLAssetDictionary::getInstance()->lookup(asset_type);
  104. if (entry)
  105. {
  106. return entry->mName;
  107. }
  108. else
  109. {
  110. return badLookup();
  111. }
  112. }
  113. // static
  114. const char *LLAssetType::lookup(LLAssetType::EType asset_type)
  115. {
  116. const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
  117. const AssetEntry *entry = dict->lookup(asset_type);
  118. if (entry)
  119. {
  120. return entry->mTypeName;
  121. }
  122. else
  123. {
  124. return badLookup().c_str();
  125. }
  126. }
  127. // static
  128. LLAssetType::EType LLAssetType::lookup(const char* name)
  129. {
  130. return lookup(ll_safe_string(name));
  131. }
  132. // static
  133. LLAssetType::EType LLAssetType::lookup(const std::string& type_name)
  134. {
  135. const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
  136. for (LLAssetDictionary::const_iterator iter = dict->begin();
  137. iter != dict->end();
  138. iter++)
  139. {
  140. const AssetEntry *entry = iter->second;
  141. if (type_name == entry->mTypeName)
  142. {
  143. return iter->first;
  144. }
  145. }
  146. return AT_NONE;
  147. }
  148. // static
  149. const char *LLAssetType::lookupHumanReadable(LLAssetType::EType asset_type)
  150. {
  151. const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
  152. const AssetEntry *entry = dict->lookup(asset_type);
  153. if (entry)
  154. {
  155. return entry->mHumanName;
  156. }
  157. else
  158. {
  159. return badLookup().c_str();
  160. }
  161. }
  162. // static
  163. LLAssetType::EType LLAssetType::lookupHumanReadable(const char* name)
  164. {
  165. return lookupHumanReadable(ll_safe_string(name));
  166. }
  167. // static
  168. LLAssetType::EType LLAssetType::lookupHumanReadable(const std::string& readable_name)
  169. {
  170. const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
  171. for (LLAssetDictionary::const_iterator iter = dict->begin();
  172. iter != dict->end();
  173. iter++)
  174. {
  175. const AssetEntry *entry = iter->second;
  176. if (entry->mHumanName && (readable_name == entry->mHumanName))
  177. {
  178. return iter->first;
  179. }
  180. }
  181. return AT_NONE;
  182. }
  183. // static
  184. bool LLAssetType::lookupCanLink(EType asset_type)
  185. {
  186. const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
  187. const AssetEntry *entry = dict->lookup(asset_type);
  188. if (entry)
  189. {
  190. return entry->mCanLink;
  191. }
  192. return false;
  193. }
  194. // static
  195. // Not adding this to dictionary since we probably will only have these two types
  196. bool LLAssetType::lookupIsLinkType(EType asset_type)
  197. {
  198. if (asset_type == AT_LINK || asset_type == AT_LINK_FOLDER)
  199. {
  200. return true;
  201. }
  202. return false;
  203. }
  204. // static
  205. const std::string &LLAssetType::badLookup()
  206. {
  207. static const std::string sBadLookup = "llassettype_bad_lookup";
  208. return sBadLookup;
  209. }
  210. // static
  211. bool LLAssetType::lookupIsAssetFetchByIDAllowed(EType asset_type)
  212. {
  213. const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
  214. const AssetEntry *entry = dict->lookup(asset_type);
  215. if (entry)
  216. {
  217. return entry->mCanFetch;
  218. }
  219. return false;
  220. }
  221. // static
  222. bool LLAssetType::lookupIsAssetIDKnowable(EType asset_type)
  223. {
  224. const LLAssetDictionary *dict = LLAssetDictionary::getInstance();
  225. const AssetEntry *entry = dict->lookup(asset_type);
  226. if (entry)
  227. {
  228. return entry->mCanKnow;
  229. }
  230. return false;
  231. }