llfoldertype.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:6k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llfoldertype.cpp
  3.  * @brief Implementatino of LLFolderType functionality.
  4.  *
  5.  * $LicenseInfo:firstyear=2001&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2001-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "linden_common.h"
  33. #include "llfoldertype.h"
  34. #include "lldictionary.h"
  35. #include "llmemory.h"
  36. #include "llsingleton.h"
  37. ///----------------------------------------------------------------------------
  38. /// Class LLFolderType
  39. ///----------------------------------------------------------------------------
  40. struct FolderEntry : public LLDictionaryEntry
  41. {
  42. FolderEntry(const std::string &type_name, // 8 character limit!
  43. bool is_protected) // can the viewer change categories of this type?
  44. :
  45. LLDictionaryEntry(type_name),
  46. mIsProtected(is_protected)
  47. {
  48. llassert(type_name.length() <= 8);
  49. }
  50. const bool mIsProtected;
  51. };
  52. class LLFolderDictionary : public LLSingleton<LLFolderDictionary>,
  53.    public LLDictionary<LLFolderType::EType, FolderEntry>
  54. {
  55. public:
  56. LLFolderDictionary();
  57. protected:
  58. virtual LLFolderType::EType notFound() const
  59. {
  60. return LLFolderType::FT_NONE;
  61. }
  62. };
  63. LLFolderDictionary::LLFolderDictionary()
  64. {
  65. //            TYPE NAME PROTECTED
  66. //          |-----------|---------|
  67. addEntry(LLFolderType::FT_TEXTURE,  new FolderEntry("texture", TRUE));
  68. addEntry(LLFolderType::FT_SOUND,  new FolderEntry("sound", TRUE));
  69. addEntry(LLFolderType::FT_CALLINGCARD,  new FolderEntry("callcard", TRUE));
  70. addEntry(LLFolderType::FT_LANDMARK,  new FolderEntry("landmark", TRUE));
  71. addEntry(LLFolderType::FT_CLOTHING,  new FolderEntry("clothing", TRUE));
  72. addEntry(LLFolderType::FT_OBJECT,  new FolderEntry("object", TRUE));
  73. addEntry(LLFolderType::FT_NOTECARD,  new FolderEntry("notecard", TRUE));
  74. addEntry(LLFolderType::FT_ROOT_INVENTORY,  new FolderEntry("root_inv", TRUE));
  75. addEntry(LLFolderType::FT_LSL_TEXT,  new FolderEntry("lsltext", TRUE));
  76. addEntry(LLFolderType::FT_BODYPART,  new FolderEntry("bodypart", TRUE));
  77. addEntry(LLFolderType::FT_TRASH,  new FolderEntry("trash", TRUE));
  78. addEntry(LLFolderType::FT_SNAPSHOT_CATEGORY,  new FolderEntry("snapshot", TRUE));
  79. addEntry(LLFolderType::FT_LOST_AND_FOUND,  new FolderEntry("lstndfnd", TRUE));
  80. addEntry(LLFolderType::FT_ANIMATION,  new FolderEntry("animatn", TRUE));
  81. addEntry(LLFolderType::FT_GESTURE,  new FolderEntry("gesture", TRUE));
  82. addEntry(LLFolderType::FT_FAVORITE,  new FolderEntry("favorite", TRUE));
  83. for (S32 ensemble_num = S32(LLFolderType::FT_ENSEMBLE_START); ensemble_num <= S32(LLFolderType::FT_ENSEMBLE_END); ensemble_num++)
  84. {
  85. addEntry(LLFolderType::EType(ensemble_num), new FolderEntry("ensemble", FALSE)); 
  86. }
  87. addEntry(LLFolderType::FT_CURRENT_OUTFIT,  new FolderEntry("current", TRUE));
  88. addEntry(LLFolderType::FT_OUTFIT,  new FolderEntry("outfit", FALSE));
  89. addEntry(LLFolderType::FT_MY_OUTFITS,  new FolderEntry("my_otfts", TRUE));
  90. addEntry(LLFolderType::FT_INBOX,  new FolderEntry("inbox", TRUE));
  91.  
  92. addEntry(LLFolderType::FT_NONE,  new FolderEntry("-1", FALSE));
  93. };
  94. // static
  95. LLFolderType::EType LLFolderType::lookup(const std::string& name)
  96. {
  97. return LLFolderDictionary::getInstance()->lookup(name);
  98. }
  99. // static
  100. const std::string &LLFolderType::lookup(LLFolderType::EType folder_type)
  101. {
  102. const FolderEntry *entry = LLFolderDictionary::getInstance()->lookup(folder_type);
  103. if (entry)
  104. {
  105. return entry->mName;
  106. }
  107. else
  108. {
  109. return badLookup();
  110. }
  111. }
  112. // static
  113. // Only ensembles and plain folders aren't protected.  "Protected" means
  114. // you can't change certain properties such as their type.
  115. bool LLFolderType::lookupIsProtectedType(EType folder_type)
  116. {
  117. const LLFolderDictionary *dict = LLFolderDictionary::getInstance();
  118. const FolderEntry *entry = dict->lookup(folder_type);
  119. if (entry)
  120. {
  121. return entry->mIsProtected;
  122. }
  123. return true;
  124. }
  125. // static
  126. bool LLFolderType::lookupIsEnsembleType(EType folder_type)
  127. {
  128. return (folder_type >= FT_ENSEMBLE_START &&
  129. folder_type <= FT_ENSEMBLE_END);
  130. }
  131. // static
  132. LLAssetType::EType LLFolderType::folderTypeToAssetType(LLFolderType::EType folder_type)
  133. {
  134. if (LLAssetType::lookup(LLAssetType::EType(folder_type)) == LLAssetType::badLookup())
  135. {
  136. llwarns << "Converting to unknown asset type " << folder_type << llendl;
  137. }
  138. return (LLAssetType::EType)folder_type;
  139. }
  140. // static
  141. LLFolderType::EType LLFolderType::assetTypeToFolderType(LLAssetType::EType asset_type)
  142. {
  143. if (LLFolderType::lookup(LLFolderType::EType(asset_type)) == LLFolderType::badLookup())
  144. {
  145. llwarns << "Converting to unknown folder type " << asset_type << llendl;
  146. }
  147. return (LLFolderType::EType)asset_type;
  148. }
  149. // static
  150. const std::string &LLFolderType::badLookup()
  151. {
  152. static const std::string sBadLookup = "llfoldertype_bad_lookup";
  153. return sBadLookup;
  154. }