Difference between revisions of "Language Specs"

From Constructive Labs
Jump to navigation Jump to search
(Created page with "== Type Coercion== type coersion, with some well defined rules, so you are not limited to the types which the method wants. Intead, it will take a variety of types. this is...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Type Coercion==
 
== Type Coercion==
type coersion, with some well defined rules, so you are not limited to the types which the method wants.  Intead, it will take a variety of types.  this is the code for the type conversion.  It defines solidly which types can be converted into which types.
+
type coercion, with some well defined rules, so you are not limited to the types which the method wants.  Instead, it will take a variety of types.  This code defines solidly which types may be converted into which types.
 
 
protected void buildCoercementMap() {
 
 
 
// Integers are convertible to floats
+
// Integers are convertible to floats
addCoercer(Integer.class, Float.class, new FloatFromInt());
+
addCoercer(Integer.class, Float.class, new FloatFromInt());
addCoercer(int.class, float.class, new FloatFromInt());
+
addCoercer(int.class, float.class, new FloatFromInt());
 
 
// Floats are convertible to ints, with loss of precision
+
// Floats are convertible to ints, with loss of precision
addCoercer(Float.class, Integer.class, new IntFromFloat());
+
addCoercer(Float.class, Integer.class, new IntFromFloat());
addCoercer(float.class, int.class, new IntFromFloat());
+
addCoercer(float.class, int.class, new IntFromFloat());
 
 
// Unboxing conversion
+
// Unboxing conversion
addCoercer(Float.class, float.class, new floatFromFloat());
+
addCoercer(Float.class, float.class, new floatFromFloat());
addCoercer(Integer.class, int.class, new intFromInt());
+
addCoercer(Integer.class, int.class, new intFromInt());
addCoercer(Double.class, double.class, new doubleFromDouble());
+
addCoercer(Double.class, double.class, new doubleFromDouble());
addCoercer(Boolean.class, boolean.class, new boolFromBoolean());
+
addCoercer(Boolean.class, boolean.class, new boolFromBoolean());
 
 
// Symbol and strings are bi-directionally interchangeable
+
// Symbol and strings are bi-directionally interchangeable
addCoercer(String.class, Symbol.class, new SymbolFromString());
+
addCoercer(String.class, Symbol.class, new SymbolFromString());
addCoercer(Symbol.class, String.class, new StringFromSymbol());
+
addCoercer(Symbol.class, String.class, new StringFromSymbol());
 
 
// Object[] arrays convert into the various desired special classes
+
// Object[] arrays convert into the various desired special classes
addCoercer(Object[].class, Vector3f.class, new Vector3fFromObjectArray());
+
addCoercer(Object[].class, Vector3f.class, new Vector3fFromObjectArray());
addCoercer(Object[].class, Color3f.class, new Color3fFromObjectArray());
+
addCoercer(Object[].class, Color3f.class, new Color3fFromObjectArray());
addCoercer(Object[].class, Quat4f.class, new Quat4fFromObjectArray());
+
addCoercer(Object[].class, Quat4f.class, new Quat4fFromObjectArray());
 
 
// HashMaps convert into the various desired special classes
+
// HashMaps convert into the various desired special classes
addCoercer(HashMap.class, Vector3f.class, new Vector3fFromHashMap());
+
addCoercer(HashMap.class, Vector3f.class, new Vector3fFromHashMap());
addCoercer(HashMap.class, Color3f.class, new Color3fFromHashMap());
+
addCoercer(HashMap.class, Color3f.class, new Color3fFromHashMap());
addCoercer(HashMap.class, Quat4f.class, new Quat4fFromHashMap());
+
addCoercer(HashMap.class, Quat4f.class, new Quat4fFromHashMap());
 
 
// various conversions between the specialized vector classes
+
// various conversions between the specialized vector classes
addCoercer(Object[].class, Color3f.class, new Color3fFromObjectArray());
+
addCoercer(Object[].class, Color3f.class, new Color3fFromObjectArray());
addCoercer(Vector4f.class, Quat4f.class, new Quat4fFromVec4f());
+
addCoercer(Vector4f.class, Quat4f.class, new Quat4fFromVec4f());
addCoercer(Vector3f.class, Color3f.class, new Color3fFromVec3f());
+
addCoercer(Vector3f.class, Color3f.class, new Color3fFromVec3f());
// strings and JSON are bi-directionally convertible
+
addCoercer(String.class, JsonNode.class, new JsonNodeFromString());
+
// strings and JSON are bi-directionally convertible
addCoercer(JsonNode.class, String.class, new StringFromJsonNode());
+
addCoercer(String.class, JsonNode.class, new JsonNodeFromString());
 +
addCoercer(JsonNode.class, String.class, new StringFromJsonNode());
 
 
// Strings and UUIDs are bi-directionally convertible
+
// Strings and UUIDs are bi-directionally convertible
addCoercer(String.class, UUID.class, new UUIDFromString());
+
addCoercer(String.class, UUID.class, new UUIDFromString());
addCoercer(UUID.class, String.class, new StringFromUUID());
+
addCoercer(UUID.class, String.class, new StringFromUUID());
 
 
// nodes can be converted into instanceID's
+
// nodes can be converted into instanceID's
addCoercer(BaseNodeCored.class, UUID.class, new InstanceIDFromBaseNodeCored());
+
addCoercer(BaseNodeCored.class, UUID.class, new InstanceIDFromBaseNodeCored());
addCoercer(DynamicPropertyNode.class, UUID.class, new InstanceIDFromBaseNodeCored());
+
addCoercer(DynamicPropertyNode.class, UUID.class, new InstanceIDFromBaseNodeCored());
 
 
//quat4f can be converted to euler
+
//quat4f can be converted to euler
addCoercer(Quat4f.class, Euler.class, new EulerFromQuat4f());
+
addCoercer(Quat4f.class, Euler.class, new EulerFromQuat4f());
addCoercer(Vector4f.class, Euler.class, new EulerFromVector4f());
+
addCoercer(Vector4f.class, Euler.class, new EulerFromVector4f());
addCoercer(Vector3f.class, Euler.class, new EulerFromVector3f());
+
addCoercer(Vector3f.class, Euler.class, new EulerFromVector3f());
}
 

Latest revision as of 12:03, 25 April 2021

Type Coercion

type coercion, with some well defined rules, so you are not limited to the types which the method wants. Instead, it will take a variety of types. This code defines solidly which types may be converted into which types.

// Integers are convertible to floats
addCoercer(Integer.class, Float.class, new FloatFromInt());
addCoercer(int.class, float.class, new FloatFromInt());
// Floats are convertible to ints, with loss of precision
addCoercer(Float.class, Integer.class, new IntFromFloat());
addCoercer(float.class, int.class, new IntFromFloat());
// Unboxing conversion
addCoercer(Float.class, float.class, new floatFromFloat());
addCoercer(Integer.class, int.class, new intFromInt());
addCoercer(Double.class, double.class, new doubleFromDouble());
addCoercer(Boolean.class, boolean.class, new boolFromBoolean());
// Symbol and strings are bi-directionally interchangeable
addCoercer(String.class, Symbol.class, new SymbolFromString());
addCoercer(Symbol.class, String.class, new StringFromSymbol());
// Object[] arrays convert into the various desired special classes
addCoercer(Object[].class, Vector3f.class, new Vector3fFromObjectArray());
addCoercer(Object[].class, Color3f.class, new Color3fFromObjectArray());
addCoercer(Object[].class, Quat4f.class, new Quat4fFromObjectArray());
// HashMaps convert into the various desired special classes
addCoercer(HashMap.class, Vector3f.class, new Vector3fFromHashMap());
addCoercer(HashMap.class, Color3f.class, new Color3fFromHashMap());
addCoercer(HashMap.class, Quat4f.class, new Quat4fFromHashMap());
// various conversions between the specialized vector classes
addCoercer(Object[].class, Color3f.class, new Color3fFromObjectArray());
addCoercer(Vector4f.class, Quat4f.class, new Quat4fFromVec4f());
addCoercer(Vector3f.class, Color3f.class, new Color3fFromVec3f());

// strings and JSON are bi-directionally convertible
addCoercer(String.class, JsonNode.class, new JsonNodeFromString());
addCoercer(JsonNode.class, String.class, new StringFromJsonNode());
// Strings and UUIDs are bi-directionally convertible
addCoercer(String.class, UUID.class, new UUIDFromString());
addCoercer(UUID.class, String.class, new StringFromUUID());
// nodes can be converted into instanceID's
addCoercer(BaseNodeCored.class, UUID.class, new InstanceIDFromBaseNodeCored());
addCoercer(DynamicPropertyNode.class, UUID.class, new InstanceIDFromBaseNodeCored());
//quat4f can be converted to euler
addCoercer(Quat4f.class, Euler.class, new EulerFromQuat4f());
addCoercer(Vector4f.class, Euler.class, new EulerFromVector4f());
addCoercer(Vector3f.class, Euler.class, new EulerFromVector3f());