llassettype.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 
00034 #include "llassettype.h"
00035 
00036 #include "llstring.h"
00037 #include "lltimer.h"
00038 
00039 // I added lookups for exact text of asset type enums in addition to the ones below, so shoot me. -Steve
00040 
00041 struct asset_info_t
00042 {
00043         LLAssetType::EType type;
00044         const char* desc;
00045 };
00046 
00047 asset_info_t asset_types[] =
00048 {
00049         { LLAssetType::AT_TEXTURE, "TEXTURE" },
00050         { LLAssetType::AT_SOUND, "SOUND" },
00051         { LLAssetType::AT_CALLINGCARD, "CALLINGCARD" },
00052         { LLAssetType::AT_LANDMARK, "LANDMARK" },
00053         { LLAssetType::AT_SCRIPT, "SCRIPT" },
00054         { LLAssetType::AT_CLOTHING, "CLOTHING" },
00055         { LLAssetType::AT_OBJECT, "OBJECT" },
00056         { LLAssetType::AT_NOTECARD, "NOTECARD" },
00057         { LLAssetType::AT_CATEGORY, "CATEGORY" },
00058         { LLAssetType::AT_ROOT_CATEGORY, "ROOT_CATEGORY" },
00059         { LLAssetType::AT_LSL_TEXT, "LSL_TEXT" },
00060         { LLAssetType::AT_LSL_BYTECODE, "LSL_BYTECODE" },
00061         { LLAssetType::AT_TEXTURE_TGA, "TEXTURE_TGA" },
00062         { LLAssetType::AT_BODYPART, "BODYPART" },
00063         { LLAssetType::AT_TRASH, "TRASH" },
00064         { LLAssetType::AT_SNAPSHOT_CATEGORY, "SNAPSHOT_CATEGORY" },
00065         { LLAssetType::AT_LOST_AND_FOUND, "LOST_AND_FOUND" },
00066         { LLAssetType::AT_SOUND_WAV, "SOUND_WAV" },
00067         { LLAssetType::AT_IMAGE_TGA, "IMAGE_TGA" },
00068         { LLAssetType::AT_IMAGE_JPEG, "IMAGE_JPEG" },
00069         { LLAssetType::AT_ANIMATION, "ANIMATION" },
00070         { LLAssetType::AT_GESTURE, "GESTURE" },
00071         { LLAssetType::AT_SIMSTATE, "SIMSTATE" },
00072         { LLAssetType::AT_NONE, "NONE" },
00073 };
00074 
00075 LLAssetType::EType LLAssetType::getType(const std::string& sin)
00076 {
00077         std::string s = sin;
00078         LLString::toUpper(s);
00079         for (S32 idx = 0; ;idx++)
00080         {
00081                 asset_info_t* info = asset_types + idx;
00082                 if (info->type == LLAssetType::AT_NONE)
00083                         break;
00084                 if (s == info->desc)
00085                         return info->type;
00086         }
00087         return LLAssetType::AT_NONE;
00088 }
00089 
00090 std::string LLAssetType::getDesc(LLAssetType::EType type)
00091 {
00092         for (S32 idx = 0; ;idx++)
00093         {
00094                 asset_info_t* info = asset_types + idx;
00095                 if (type == info->type)
00096                         return info->desc;
00097                 if (info->type == LLAssetType::AT_NONE)
00098                         break;
00099         }
00100         return "BAD TYPE";
00101 }
00102 
00103 //============================================================================
00104 
00105 // The asset type names are limited to 8 characters.
00106 // static
00107 const char* LLAssetType::mAssetTypeNames[LLAssetType::AT_COUNT] =
00108 { 
00109         "texture",
00110         "sound",
00111         "callcard",
00112         "landmark",
00113         "script",
00114         "clothing",
00115         "object",
00116         "notecard",
00117         "category",
00118         "root",
00119         "lsltext",
00120         "lslbyte",
00121         "txtr_tga",// Intentionally spelled this way.  Limited to eight characters.
00122         "bodypart",
00123         "trash",
00124         "snapshot",
00125         "lstndfnd",
00126         "snd_wav",
00127         "img_tga",
00128         "jpeg",
00129         "animatn",
00130         "gesture",
00131         "simstate",
00132 };
00133 
00134 // This table is meant for decoding to human readable form. Put any
00135 // and as many printable characters you want in each one.
00136 // See also llinventory.cpp INVENTORY_TYPE_HUMAN_NAMES
00137 const char* LLAssetType::mAssetTypeHumanNames[LLAssetType::AT_COUNT] =
00138 { 
00139         "texture",
00140         "sound",
00141         "calling card",
00142         "landmark",
00143         "legacy script",
00144         "clothing",
00145         "object",
00146         "note card",
00147         "folder",
00148         "root",
00149         "lsl2 script",
00150         "lsl bytecode",
00151         "tga texture",
00152         "body part",
00153         "trash",
00154         "snapshot",
00155         "lost and found",
00156         "sound",
00157         "targa image",
00158         "jpeg image",
00159         "animation",
00160         "gesture",
00161         "simstate",
00162 };
00163 
00167 
00168 // static
00169 const char* LLAssetType::lookup( LLAssetType::EType type )
00170 {
00171         if( (type >= 0) && (type < AT_COUNT ))
00172         {
00173                 return mAssetTypeNames[ S32( type ) ];
00174         }
00175         else
00176         {
00177                 return "-1";
00178         }
00179 }
00180 
00181 // static
00182 LLAssetType::EType LLAssetType::lookup( const char* name )
00183 {
00184         for( S32 i = 0; i < AT_COUNT; i++ )
00185         {
00186                 if( 0 == strcmp(name, mAssetTypeNames[i]) )
00187                 {
00188                         // match
00189                         return (EType)i;
00190                 }
00191         }
00192         return AT_NONE;
00193 }
00194 
00195 // static
00196 const char* LLAssetType::lookupHumanReadable(LLAssetType::EType type)
00197 {
00198         if( (type >= 0) && (type < AT_COUNT ))
00199         {
00200                 return mAssetTypeHumanNames[S32(type)];
00201         }
00202         else
00203         {
00204                 return NULL;
00205         }
00206 }
00207 
00208 // static
00209 LLAssetType::EType LLAssetType::lookupHumanReadable( const char* name )
00210 {
00211         for( S32 i = 0; i < AT_COUNT; i++ )
00212         {
00213                 if( 0 == strcmp(name, mAssetTypeHumanNames[i]) )
00214                 {
00215                         // match
00216                         return (EType)i;
00217                 }
00218         }
00219         return AT_NONE;
00220 }
00221 
00222 EDragAndDropType LLAssetType::lookupDragAndDropType( EType asset )
00223 {
00224         switch( asset )
00225         {
00226         case AT_TEXTURE:                return DAD_TEXTURE;
00227         case AT_SOUND:                  return DAD_SOUND;
00228         case AT_CALLINGCARD:    return DAD_CALLINGCARD;
00229         case AT_LANDMARK:               return DAD_LANDMARK;
00230         case AT_SCRIPT:                 return DAD_NONE;
00231         case AT_CLOTHING:               return DAD_CLOTHING;
00232         case AT_OBJECT:                 return DAD_OBJECT;
00233         case AT_NOTECARD:               return DAD_NOTECARD;
00234         case AT_CATEGORY:               return DAD_CATEGORY;
00235         case AT_ROOT_CATEGORY:  return DAD_ROOT_CATEGORY;
00236         case AT_LSL_TEXT:               return DAD_SCRIPT;
00237         case AT_BODYPART:               return DAD_BODYPART;
00238         case AT_ANIMATION:              return DAD_ANIMATION;
00239         case AT_GESTURE:                return DAD_GESTURE;
00240         default:                                return DAD_NONE;
00241         };
00242 }
00243 
00244 // static. Generate a good default description
00245 void LLAssetType::generateDescriptionFor(LLAssetType::EType type,
00246                                                                                  std::string& desc)
00247 {
00248         const S32 BUF_SIZE = 30;
00249         char time_str[BUF_SIZE];        /* Flawfinder: ignore */
00250         time_t now;
00251         time(&now);
00252         memset(time_str, '\0', BUF_SIZE);
00253         strftime(time_str, BUF_SIZE - 1, "%Y-%m-%d %H:%M:%S ", localtime(&now));
00254         desc.assign(time_str);
00255         desc.append(LLAssetType::lookupHumanReadable(type));
00256 }

Generated on Fri May 16 08:32:02 2008 for SecondLife by  doxygen 1.5.5