Skip to content

Commit 8aaa33a

Browse files
author
Anders Modén
committed
Merge branch 'release/1.0'
2 parents e5b2dc1 + 8c7800b commit 8aaa33a

24 files changed

Lines changed: 446 additions & 26 deletions

Assets/Plugins/x64/gzBase64.dll

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
1.5 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

Assets/Saab/GizmoSDK/GizmoBase/DynamicType.cs

Lines changed: 133 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,130 @@ public DynamicType(IntPtr nativeReference) : base(nativeReference) { }
125125

126126
public DynamicType(Reference reference) : base(DynamicType_create_reference(reference.GetNativeReference())) { }
127127

128+
public static DynamicType CreateDynamicType(object obj)
129+
{
130+
if (obj == null)
131+
return new DynamicType();
132+
133+
if (obj is DynamicType)
134+
return obj as DynamicType;
135+
136+
if(obj is DynamicTypeContainer)
137+
return (DynamicType)(obj as DynamicTypeContainer);
138+
139+
if (obj is DynamicTypeArray)
140+
return (DynamicType)(obj as DynamicTypeArray);
141+
142+
if (obj.GetType() == typeof(string))
143+
return new DynamicType((string)obj);
144+
145+
if (obj.GetType() == typeof(Int64))
146+
return new DynamicTypeInt64((Int64)obj);
147+
148+
if (obj.GetType() == typeof(UInt64))
149+
return new DynamicTypeInt64((UInt64)obj);
150+
151+
if (obj.GetType() == typeof(Vec2))
152+
return new DynamicType((Vec2)obj);
153+
154+
if (obj.GetType() == typeof(Vec3))
155+
return new DynamicType((Vec3)obj);
156+
157+
if (obj.GetType() == typeof(Vec4))
158+
return new DynamicType((Vec4)obj);
159+
160+
if (obj.GetType() == typeof(Guid))
161+
return new DynamicType((Guid)obj);
162+
163+
if (obj.GetType() == typeof(Reference))
164+
return new DynamicType((Reference)obj);
165+
166+
if (obj.GetType().IsEnum)
167+
{
168+
if (Marshal.SizeOf(Enum.GetUnderlyingType(obj.GetType())) <= sizeof(UInt32))
169+
return new DynamicType((UInt32)Convert.ChangeType(obj, typeof(UInt32)));
170+
else
171+
return new DynamicType((UInt64)Convert.ChangeType(obj, typeof(UInt64)));
172+
}
173+
174+
return new DynamicType((double)Convert.ChangeType(obj,typeof(double))); // default to double
175+
}
176+
177+
public object GetObject(System.Type t)
178+
{
179+
if (t==typeof(DynamicType))
180+
return this;
181+
182+
if (t.IsSubclassOf(typeof(DynamicType)))
183+
return this;
184+
185+
if (t == typeof(DynamicTypeArray))
186+
return (DynamicTypeArray)this;
187+
188+
if (t.IsSubclassOf(typeof(DynamicTypeArray)))
189+
{
190+
object o = Activator.CreateInstance(t);
191+
192+
((DynamicTypeArray)o).Set(this);
193+
194+
return o;
195+
}
196+
197+
if (t == typeof(DynamicTypeContainer))
198+
return (DynamicTypeContainer)this;
199+
200+
if (t.IsSubclassOf(typeof(DynamicTypeContainer)))
201+
{
202+
object o=Activator.CreateInstance(t);
203+
204+
((DynamicTypeContainer)o).Set(this);
205+
206+
return o;
207+
}
208+
if (t==typeof(string))
209+
return (string)this;
210+
211+
if (t == typeof(UInt64))
212+
return (UInt64)this;
213+
214+
if (t == typeof(Int64))
215+
return (Int64)this;
216+
217+
if (t == typeof(Vec2))
218+
return (Vec2)this;
219+
220+
if (t == typeof(Vec3))
221+
return (Vec3)this;
222+
223+
if (t == typeof(Vec4))
224+
return (Vec4)this;
225+
226+
if (t == typeof(Guid))
227+
return (Guid)this;
228+
229+
if (t == typeof(Reference))
230+
return (Reference)this;
231+
232+
if (t.IsSubclassOf(typeof(Reference)))
233+
return (Reference)this;
234+
235+
if (t.IsEnum)
236+
{
237+
if(Marshal.SizeOf(Enum.GetUnderlyingType(t))<=sizeof(UInt32))
238+
return Enum.ToObject(t, (UInt32)this);
239+
else
240+
return Enum.ToObject(t, (UInt64)this);
241+
}
242+
243+
return Convert.ChangeType(GetNumber(), t);
244+
}
245+
246+
public bool IsVoid()
247+
{
248+
return Is("void");
249+
}
250+
251+
128252
public string GetDynamicType()
129253
{
130254
if (!IsValid())
@@ -154,6 +278,7 @@ public Vec2 GetVec2()
154278
if (!IsValid())
155279
throw (new Exception("DynamicType is not VALID"));
156280

281+
157282
return DynamicType_getVec2(GetNativeReference());
158283
}
159284

@@ -170,6 +295,9 @@ public Reference GetReference()
170295
if (!IsValid())
171296
throw (new Exception("DynamicType is not VALID"));
172297

298+
if (IsVoid())
299+
return null;
300+
173301
return new Reference(DynamicType_getReference(GetNativeReference()));
174302
}
175303

@@ -192,15 +320,18 @@ public Guid GetGuid()
192320
public string GetString()
193321
{
194322
if (!IsValid())
195-
return "Invalid";
323+
return null;
324+
325+
if (IsVoid())
326+
return null;
196327

197328
return Marshal.PtrToStringUni(DynamicType_getString(GetNativeReference()));
198329
}
199330

200331
public string AsString(bool stripXML = true, bool skipDynTag = true, string tagName="data")
201332
{
202333
if (!IsValid())
203-
return "Invalid";
334+
return null;
204335

205336
return Marshal.PtrToStringUni(DynamicType_asString(GetNativeReference(),stripXML,skipDynTag,tagName));
206337
}

Assets/Saab/GizmoSDK/GizmoBase/DynamicTypeArray.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,18 @@ public DynamicTypeArray(DynamicType data) : base(DynamicTypeArray_unpack_array(d
105105
throw (new Exception("DynamicType is not an ARRAY"));
106106
}
107107

108-
108+
public void Set(DynamicType t)
109+
{
110+
if (t == null)
111+
return;
112+
113+
if (!t.Is(DynamicType.Type.ARRAY))
114+
return;
115+
116+
Reset(DynamicTypeArray_unpack_array(t.GetNativeReference()));
117+
}
118+
119+
109120
public int IndexOf(DynamicType item)
110121
{
111122
return DynamicTypeArray_index_of(GetNativeReference(),item.GetNativeReference());

Assets/Saab/GizmoSDK/GizmoBase/DynamicTypeContainer.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public static implicit operator DynamicType(DynamicTypeContainer cont)
7676
if (cont == null)
7777
return null;
7878

79+
if (cont.GetType().IsDefined(typeof(DynamicTypePropertyAutoStore), true))
80+
cont.StorePropertiesAndFields();
81+
7982
return new DynamicType(DynamicTypeContainer_pack_cont(cont.GetNativeReference()));
8083
}
8184

@@ -95,8 +98,24 @@ public DynamicTypeContainer(DynamicType data) : base(DynamicTypeContainer_unpac
9598

9699
if (GetNativeReference()==IntPtr.Zero)
97100
throw (new Exception("DynamicType is not a CONTAINER"));
101+
102+
}
103+
104+
public void Set(DynamicType t)
105+
{
106+
if (t == null)
107+
return;
108+
109+
if (!t.Is(DynamicType.Type.CONTAINER))
110+
return;
111+
112+
Reset(DynamicTypeContainer_unpack_cont(t.GetNativeReference()));
113+
114+
if (GetType().IsDefined(typeof(DynamicTypePropertyAutoRestore), true))
115+
RestorePropertiesAndFields();
98116
}
99117

118+
100119
public void SetAttribute(string name, DynamicType value)
101120
{
102121
if (name == null)
@@ -129,6 +148,38 @@ public override string ToString()
129148
return ((DynamicType)(this)).AsString();
130149
}
131150

151+
// --- Reflection mechanisms --------------------------------
152+
153+
public void StorePropertiesAndFields(bool allProperties = false)
154+
{
155+
foreach (System.Reflection.PropertyInfo prop in GetType().GetProperties())
156+
{
157+
if (allProperties || Attribute.IsDefined(prop, typeof(DynamicTypeProperty)))
158+
SetAttribute(prop.Name, DynamicType.CreateDynamicType(prop.GetValue(this)));
159+
}
160+
161+
foreach (System.Reflection.FieldInfo field in GetType().GetFields())
162+
{
163+
if (allProperties || Attribute.IsDefined(field, typeof(DynamicTypeProperty)))
164+
SetAttribute(field.Name, DynamicType.CreateDynamicType(field.GetValue(this)));
165+
}
166+
}
167+
168+
public void RestorePropertiesAndFields(bool allProperties = false)
169+
{
170+
foreach (System.Reflection.PropertyInfo prop in GetType().GetProperties())
171+
{
172+
if (allProperties || Attribute.IsDefined(prop, typeof(DynamicTypeProperty)))
173+
prop.SetValue(this, GetAttribute(prop.Name).GetObject(prop.PropertyType));
174+
}
175+
176+
foreach (System.Reflection.FieldInfo field in GetType().GetFields())
177+
{
178+
if (allProperties || Attribute.IsDefined(field, typeof(DynamicTypeProperty)))
179+
field.SetValue(this, GetAttribute(field.Name).GetObject(field.FieldType));
180+
}
181+
}
182+
132183
#region ---------------------- private -------------------------------------
133184

134185
[DllImport(Platform.BRIDGE, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//******************************************************************************
2+
// File : DynamicTypeProperty.cs
3+
// Module : GizmoBase C#
4+
// Description : C# Bridge to gzDynamicType property classes
5+
// Author : Anders Modén
6+
// Product : GizmoBase 2.10.1
7+
//
8+
// Copyright © 2003- Saab Training Systems AB, Sweden
9+
//
10+
// NOTE: GizmoBase is a platform abstraction utility layer for C++. It contains
11+
// design patterns and C++ solutions for the advanced programmer.
12+
//
13+
//
14+
// Revision History...
15+
//
16+
// Who Date Description
17+
//
18+
// AMO 180301 Created file
19+
//
20+
//******************************************************************************
21+
22+
using System;
23+
using System.Runtime.InteropServices;
24+
using GizmoSDK.GizmoBase;
25+
26+
27+
28+
namespace GizmoSDK
29+
{
30+
namespace GizmoBase
31+
{
32+
[System.AttributeUsage(System.AttributeTargets.Property| System.AttributeTargets.Field, AllowMultiple = false)]
33+
public class DynamicTypeProperty : System.Attribute
34+
{
35+
}
36+
37+
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple = false)]
38+
public class DynamicTypePropertyAutoStore : System.Attribute
39+
{
40+
}
41+
42+
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple = false)]
43+
public class DynamicTypePropertyAutoRestore : System.Attribute
44+
{
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)