diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llcommon/llsdutil.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llcommon/llsdutil.cpp | 224 |
1 files changed, 224 insertions, 0 deletions
diff --git a/linden/indra/llcommon/llsdutil.cpp b/linden/indra/llcommon/llsdutil.cpp new file mode 100644 index 0000000..f111039 --- /dev/null +++ b/linden/indra/llcommon/llsdutil.cpp | |||
@@ -0,0 +1,224 @@ | |||
1 | /** | ||
2 | * @file llsdutil.cpp | ||
3 | * @author Phoenix | ||
4 | * @date 2006-05-24 | ||
5 | * @brief Implementation of classes, functions, etc, for using structured data. | ||
6 | * | ||
7 | * Copyright (c) 2006-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #include "linden_common.h" | ||
31 | |||
32 | #include "llsdutil.h" | ||
33 | |||
34 | #if LL_WINDOWS | ||
35 | # define WIN32_LEAN_AND_MEAN | ||
36 | # include <winsock2.h> // for htonl | ||
37 | #elif LL_LINUX | ||
38 | # include <netinet/in.h> | ||
39 | #elif LL_DARWIN | ||
40 | # include <arpa/inet.h> | ||
41 | #endif | ||
42 | |||
43 | |||
44 | |||
45 | // vector3 | ||
46 | LLSD ll_sd_from_vector3(const LLVector3& vec) | ||
47 | { | ||
48 | LLSD rv; | ||
49 | rv.append((F64)vec.mV[VX]); | ||
50 | rv.append((F64)vec.mV[VY]); | ||
51 | rv.append((F64)vec.mV[VZ]); | ||
52 | return rv; | ||
53 | } | ||
54 | |||
55 | LLVector3 ll_vector3_from_sd(const LLSD& sd, S32 start_index) | ||
56 | { | ||
57 | LLVector3 rv; | ||
58 | rv.mV[VX] = (F32)sd[start_index].asReal(); | ||
59 | rv.mV[VY] = (F32)sd[++start_index].asReal(); | ||
60 | rv.mV[VZ] = (F32)sd[++start_index].asReal(); | ||
61 | return rv; | ||
62 | } | ||
63 | |||
64 | // vector3d | ||
65 | LLSD ll_sd_from_vector3d(const LLVector3d& vec) | ||
66 | { | ||
67 | LLSD rv; | ||
68 | rv.append(vec.mdV[VX]); | ||
69 | rv.append(vec.mdV[VY]); | ||
70 | rv.append(vec.mdV[VZ]); | ||
71 | return rv; | ||
72 | } | ||
73 | |||
74 | LLVector3d ll_vector3d_from_sd(const LLSD& sd, S32 start_index) | ||
75 | { | ||
76 | LLVector3d rv; | ||
77 | rv.mdV[VX] = sd[start_index].asReal(); | ||
78 | rv.mdV[VY] = sd[++start_index].asReal(); | ||
79 | rv.mdV[VZ] = sd[++start_index].asReal(); | ||
80 | return rv; | ||
81 | } | ||
82 | |||
83 | //vector2 | ||
84 | LLSD ll_sd_from_vector2(const LLVector2& vec) | ||
85 | { | ||
86 | LLSD rv; | ||
87 | rv.append((F64)vec.mV[VX]); | ||
88 | rv.append((F64)vec.mV[VY]); | ||
89 | return rv; | ||
90 | } | ||
91 | |||
92 | LLVector2 ll_vector2_from_sd(const LLSD& sd) | ||
93 | { | ||
94 | LLVector2 rv; | ||
95 | rv.mV[VX] = (F32)sd[0].asReal(); | ||
96 | rv.mV[VY] = (F32)sd[1].asReal(); | ||
97 | return rv; | ||
98 | } | ||
99 | |||
100 | // Quaternion | ||
101 | LLSD ll_sd_from_quaternion(const LLQuaternion& quat) | ||
102 | { | ||
103 | LLSD rv; | ||
104 | rv.append((F64)quat.mQ[VX]); | ||
105 | rv.append((F64)quat.mQ[VY]); | ||
106 | rv.append((F64)quat.mQ[VZ]); | ||
107 | rv.append((F64)quat.mQ[VW]); | ||
108 | return rv; | ||
109 | } | ||
110 | |||
111 | LLQuaternion ll_quaternion_from_sd(const LLSD& sd) | ||
112 | { | ||
113 | LLQuaternion quat; | ||
114 | quat.mQ[VX] = (F32)sd[0].asReal(); | ||
115 | quat.mQ[VY] = (F32)sd[1].asReal(); | ||
116 | quat.mQ[VZ] = (F32)sd[2].asReal(); | ||
117 | quat.mQ[VW] = (F32)sd[3].asReal(); | ||
118 | return quat; | ||
119 | } | ||
120 | |||
121 | // color4 | ||
122 | LLSD ll_sd_from_color4(const LLColor4& c) | ||
123 | { | ||
124 | LLSD rv; | ||
125 | rv.append(c.mV[0]); | ||
126 | rv.append(c.mV[1]); | ||
127 | rv.append(c.mV[2]); | ||
128 | rv.append(c.mV[3]); | ||
129 | return rv; | ||
130 | } | ||
131 | |||
132 | LLColor4 ll_color4_from_sd(const LLSD& sd) | ||
133 | { | ||
134 | LLColor4 c; | ||
135 | c.mV[0] = (F32)sd[0].asReal(); | ||
136 | c.mV[1] = (F32)sd[1].asReal(); | ||
137 | c.mV[2] = (F32)sd[2].asReal(); | ||
138 | c.mV[3] = (F32)sd[3].asReal(); | ||
139 | return c; | ||
140 | } | ||
141 | |||
142 | // U32 | ||
143 | LLSD ll_sd_from_U32(const U32 val) | ||
144 | { | ||
145 | std::vector<U8> v; | ||
146 | U32 net_order = htonl(val); | ||
147 | |||
148 | v.resize(4); | ||
149 | memcpy(&(v[0]), &net_order, 4); /* Flawfinder: ignore */ | ||
150 | |||
151 | return LLSD(v); | ||
152 | } | ||
153 | |||
154 | U32 ll_U32_from_sd(const LLSD& sd) | ||
155 | { | ||
156 | U32 ret; | ||
157 | std::vector<U8> v = sd.asBinary(); | ||
158 | if (v.size() < 4) | ||
159 | { | ||
160 | return 0; | ||
161 | } | ||
162 | memcpy(&ret, &(v[0]), 4); /* Flawfinder: ignore */ | ||
163 | ret = ntohl(ret); | ||
164 | return ret; | ||
165 | } | ||
166 | |||
167 | //U64 | ||
168 | LLSD ll_sd_from_U64(const U64 val) | ||
169 | { | ||
170 | std::vector<U8> v; | ||
171 | U32 high, low; | ||
172 | |||
173 | high = (U32)(val >> 32); | ||
174 | low = (U32)val; | ||
175 | high = htonl(high); | ||
176 | low = htonl(low); | ||
177 | |||
178 | v.resize(8); | ||
179 | memcpy(&(v[0]), &high, 4); /* Flawfinder: ignore */ | ||
180 | memcpy(&(v[4]), &low, 4); /* Flawfinder: ignore */ | ||
181 | |||
182 | return LLSD(v); | ||
183 | } | ||
184 | |||
185 | U64 ll_U64_from_sd(const LLSD& sd) | ||
186 | { | ||
187 | U32 high, low; | ||
188 | std::vector<U8> v = sd.asBinary(); | ||
189 | |||
190 | if (v.size() < 8) | ||
191 | { | ||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | memcpy(&high, &(v[0]), 4); /* Flawfinder: ignore */ | ||
196 | memcpy(&low, &(v[4]), 4); /* Flawfinder: ignore */ | ||
197 | high = ntohl(high); | ||
198 | low = ntohl(low); | ||
199 | |||
200 | return ((U64)high) << 32 | low; | ||
201 | } | ||
202 | |||
203 | // IP Address (stored in net order in a U32, so don't need swizzling) | ||
204 | LLSD ll_sd_from_ipaddr(const U32 val) | ||
205 | { | ||
206 | std::vector<U8> v; | ||
207 | |||
208 | v.resize(4); | ||
209 | memcpy(&(v[0]), &val, 4); /* Flawfinder: ignore */ | ||
210 | |||
211 | return LLSD(v); | ||
212 | } | ||
213 | |||
214 | U32 ll_ipaddr_from_sd(const LLSD& sd) | ||
215 | { | ||
216 | U32 ret; | ||
217 | std::vector<U8> v = sd.asBinary(); | ||
218 | if (v.size() < 4) | ||
219 | { | ||
220 | return 0; | ||
221 | } | ||
222 | memcpy(&ret, &(v[0]), 4); /* Flawfinder: ignore */ | ||
223 | return ret; | ||
224 | } | ||