llnamevalue.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**
  2. * @file llnamevalue.h
  3. * @brief class for defining name value pairs.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, 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. #ifndef LL_LLNAMEVALUE_H
  33. #define LL_LLNAMEVALUE_H
  34. // As of January 2008, I believe we only use the following name-value pairs.
  35. // This is hard to prove because they are initialized from strings. JC
  36. //
  37. // FirstName STRING
  38. // LastName STRING
  39. // AttachPt U32
  40. // AttachmentItemId STRING
  41. // Title STRING
  42. // AttachmentOffset VEC3
  43. // AttachmentOrientation VEC3
  44. // SitObject STRING
  45. // SitPosition VEC3
  46. #include "lldbstrings.h"
  47. #include "llmath.h"
  48. #include "llstringtable.h"
  49. #include "llvector3.h"
  50. class LLNameValue;
  51. class LLStringTable;
  52. typedef enum e_name_value_types
  53. {
  54. NVT_NULL,
  55. NVT_STRING,
  56. NVT_F32,
  57. NVT_S32,
  58. NVT_VEC3,
  59. NVT_U32,
  60. NVT_CAMERA, // Deprecated, but leaving in case removing this will cause problems
  61. NVT_ASSET,
  62. NVT_U64,
  63. NVT_EOF
  64. } ENameValueType;
  65. typedef enum e_name_value_class
  66. {
  67. NVC_NULL,
  68. NVC_READ_ONLY,
  69. NVC_READ_WRITE,
  70. NVC_EOF
  71. } ENameValueClass;
  72. typedef enum e_name_value_sento
  73. {
  74. NVS_NULL,
  75. NVS_SIM,
  76. NVS_DATA_SIM,
  77. NVS_SIM_VIEWER,
  78. NVS_DATA_SIM_VIEWER,
  79. NVS_EOF
  80. } ENameValueSendto;
  81. // NameValues can always be "printed" into a buffer of this length.
  82. constexpr U32 NAME_VALUE_BUF_SIZE = 1024;
  83. constexpr U32 NAME_VALUE_TYPE_STRING_LENGTH = 8;
  84. constexpr U32 NAME_VALUE_CLASS_STRING_LENGTH = 16;
  85. constexpr U32 NAME_VALUE_SENDTO_STRING_LENGTH = 18;
  86. constexpr U32 NAME_VALUE_DATA_SIZE = NAME_VALUE_BUF_SIZE -
  87. (DB_NV_NAME_BUF_SIZE +
  88. NAME_VALUE_TYPE_STRING_LENGTH +
  89. NAME_VALUE_CLASS_STRING_LENGTH +
  90. NAME_VALUE_SENDTO_STRING_LENGTH);
  91. extern char NameValueTypeStrings[NVT_EOF][NAME_VALUE_TYPE_STRING_LENGTH];
  92. extern char NameValueClassStrings[NVC_EOF][NAME_VALUE_CLASS_STRING_LENGTH];
  93. extern char NameValueSendtoStrings[NVS_EOF][NAME_VALUE_SENDTO_STRING_LENGTH];
  94. typedef union u_name_value_reference
  95. {
  96. char* string;
  97. F32* f32;
  98. S32* s32;
  99. LLVector3* vec3;
  100. U32* u32;
  101. U64* u64;
  102. } UNameValueReference;
  103. class LLNameValue
  104. {
  105. protected:
  106. LOG_CLASS(LLNameValue);
  107. public:
  108. void baseInit();
  109. void init(const char* name, const char* data, const char* type,
  110. const char* nvclass, const char* nvsendto);
  111. LLNameValue();
  112. LLNameValue(const char* data);
  113. LLNameValue(const char* name, const char* type, const char* nvclass);
  114. LLNameValue(const char* name, const char* data, const char* type,
  115. const char* nvclass);
  116. LLNameValue(const char* name, const char* data, const char* type,
  117. const char* nvclass, const char* nvsendto);
  118. ~LLNameValue();
  119. char* getString();
  120. const char* getAsset() const;
  121. F32* getF32();
  122. S32* getS32();
  123. void getVec3(LLVector3 &vec);
  124. LLVector3* getVec3();
  125. U32* getU32();
  126. U64* getU64();
  127. LL_INLINE const char* getType() const { return mStringType; }
  128. LL_INLINE const char* getClass() const { return mStringClass; }
  129. LL_INLINE const char* getSendto() const { return mStringSendto; }
  130. bool sendToData() const;
  131. bool sendToViewer() const;
  132. void callCallback();
  133. std::string printNameValue() const;
  134. std::string printData() const;
  135. LL_INLINE ENameValueType getTypeEnum() const { return mType; }
  136. LL_INLINE ENameValueClass getClassEnum() const { return mClass; }
  137. LL_INLINE ENameValueSendto getSendtoEnum() const { return mSendto; }
  138. LLNameValue& operator=(const LLNameValue& a);
  139. void setString(const char* a);
  140. void setAsset(const char* a);
  141. void setF32(F32 a);
  142. void setS32(S32 a);
  143. void setVec3(const LLVector3& a);
  144. void setU32(U32 a);
  145. friend std::ostream& operator<<(std::ostream& s, const LLNameValue& a);
  146. private:
  147. void printNameValue(std::ostream& s);
  148. public:
  149. char* mName;
  150. char* mStringType;
  151. ENameValueType mType;
  152. char* mStringClass;
  153. ENameValueClass mClass;
  154. char* mStringSendto;
  155. ENameValueSendto mSendto;
  156. UNameValueReference mNameValueReference;
  157. LLStringTable* mNVNameTable;
  158. };
  159. extern LLStringTable gNVNameTable;
  160. #endif