PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/llnamevalue.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 183 lines | 112 code | 32 blank | 39 comment | 0 complexity | 1063f04dc447b045b2878757f8bbfcd6 MD5 | raw file
  1/** 
  2 * @file llnamevalue.h
  3 * @brief class for defining name value pairs.
  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#ifndef LL_LLNAMEVALUE_H
 28#define LL_LLNAMEVALUE_H
 29
 30// As of January 2008, I believe we only use the following name-value
 31// pairs.  This is hard to prove because they are initialized from
 32// strings.  JC
 33//
 34// FirstName STRING
 35// LastName STRING
 36// AttachPt U32
 37// AttachmentItemId STRING
 38// Title STRING
 39// AttachmentOffset VEC3
 40// AttachmentOrientation VEC3
 41// SitObject STRING
 42// SitPosition VEC3
 43
 44#include "string_table.h"
 45#include "llmath.h"
 46#include "v3math.h"
 47#include "lldbstrings.h"
 48
 49class LLNameValue;
 50class LLStringTable;
 51
 52typedef 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
 66typedef enum e_name_value_class
 67{
 68	NVC_NULL,
 69	NVC_READ_ONLY,
 70	NVC_READ_WRITE,
 71	NVC_EOF
 72} ENameValueClass;
 73
 74typedef enum e_name_value_sento
 75{
 76	NVS_NULL,
 77	NVS_SIM,
 78	NVS_DATA_SIM,
 79	NVS_SIM_VIEWER,
 80	NVS_DATA_SIM_VIEWER,
 81	NVS_EOF
 82} ENameValueSendto;
 83
 84
 85// NameValues can always be "printed" into a buffer of this length.
 86const U32 NAME_VALUE_BUF_SIZE = 1024;
 87
 88
 89const U32 NAME_VALUE_TYPE_STRING_LENGTH = 8;
 90const U32 NAME_VALUE_CLASS_STRING_LENGTH = 16;
 91const U32 NAME_VALUE_SENDTO_STRING_LENGTH = 18;
 92const U32 NAME_VALUE_DATA_SIZE = 
 93			NAME_VALUE_BUF_SIZE - 
 94			( DB_NV_NAME_BUF_SIZE +
 95			NAME_VALUE_TYPE_STRING_LENGTH +
 96			NAME_VALUE_CLASS_STRING_LENGTH + 
 97			NAME_VALUE_SENDTO_STRING_LENGTH );
 98
 99
100extern char NameValueTypeStrings[NVT_EOF][NAME_VALUE_TYPE_STRING_LENGTH];			/* Flawfinder: Ignore */
101extern char NameValueClassStrings[NVC_EOF][NAME_VALUE_CLASS_STRING_LENGTH];		/* Flawfinder: Ignore */
102extern char NameValueSendtoStrings[NVS_EOF][NAME_VALUE_SENDTO_STRING_LENGTH];		/* Flawfinder: Ignore */
103
104typedef union u_name_value_reference
105{
106	char		*string;
107	F32			*f32;
108	S32			*s32;
109	LLVector3	*vec3;
110	U32			*u32;
111	U64			*u64;
112} UNameValueReference;
113
114
115class LLNameValue
116{
117public:
118	void baseInit();
119	void init(const char *name, const char *data, const char *type, const char *nvclass, const char *nvsendto );
120
121	LLNameValue();
122	LLNameValue(const char *data);
123	LLNameValue(const char *name, const char *type, const char *nvclass );
124	LLNameValue(const char *name, const char *data, const char *type, const char *nvclass );
125	LLNameValue(const char *name, const char *data, const char *type, const char *nvclass, const char *nvsendto );
126
127	~LLNameValue();
128
129	char			*getString();
130	const char		*getAsset() const;
131	F32				*getF32();
132	S32				*getS32();
133	void			getVec3(LLVector3 &vec);
134	LLVector3		*getVec3();
135	U32				*getU32();
136	U64				*getU64();
137
138	const char		*getType() const		{ return mStringType; }
139	const char		*getClass() const		{ return mStringClass; }
140	const char		*getSendto() const		{ return mStringSendto; }
141
142	BOOL			sendToData() const;
143	BOOL			sendToViewer() const;
144
145	void			callCallback();
146	std::string		printNameValue() const;
147	std::string		printData() const;
148	
149	ENameValueType		getTypeEnum() const		{ return mType; }
150	ENameValueClass		getClassEnum() const	{ return mClass; }
151	ENameValueSendto	getSendtoEnum() const	{ return mSendto; }
152
153	LLNameValue		&operator=(const LLNameValue &a);
154	void			setString(const char *a);
155	void			setAsset(const char *a);
156	void			setF32(const F32 a);
157	void			setS32(const S32 a);
158	void			setVec3(const LLVector3 &a);
159	void			setU32(const U32 a);
160
161	friend std::ostream&		operator<<(std::ostream& s, const LLNameValue &a);
162
163private:
164	void			printNameValue(std::ostream& s);
165	
166public:
167	char						*mName;
168
169	char						*mStringType;
170	ENameValueType				mType;
171	char						*mStringClass;
172	ENameValueClass				mClass;
173	char						*mStringSendto;
174	ENameValueSendto			mSendto;
175
176	UNameValueReference			mNameValueReference;
177	LLStringTable				*mNVNameTable;
178};
179
180extern LLStringTable	gNVNameTable;
181
182
183#endif