diff --git a/upnp/statevalue.go b/upnp/statevalue.go index 763a10e9..ca8cb2f7 100644 --- a/upnp/statevalue.go +++ b/upnp/statevalue.go @@ -36,19 +36,6 @@ type StateValue struct { marshal ValueSerializer } -// IsNumeric checks whether a given StateValue model represents a numeric value or -// not. Numeric types are defined as those that can be used to store number-like -// values. The following types are considered numeric: UI1, UI2, UI4, I1, I2, -// I4, Int, R4, R8, Number and Fixed14_4. -// -// t: StateVarType to check if it's a numeric type or not. -// -// Returns true if the given StateValue represents a numeric value; false -// otherwise. -func (sv StateValue) IsNumeric() bool { - return sv.valueType.IsNumeric() -} - // BitSize returns the number of bits that will be used to represent values // when this type is used in an UPnP State Variable. The returned value can be // either 8, 16, 24, 32, or 64, depending on whether t is Byte, Boolean, I2, Ui2, diff --git a/upnp/statevalue_typechecking.go b/upnp/statevalue_typechecking.go index d5eaa436..4734feeb 100644 --- a/upnp/statevalue_typechecking.go +++ b/upnp/statevalue_typechecking.go @@ -1,5 +1,18 @@ package upnp +// IsNumeric checks whether a given StateValue model represents a numeric value or +// not. Numeric types are defined as those that can be used to store number-like +// values. The following types are considered numeric: UI1, UI2, UI4, I1, I2, +// I4, Int, R4, R8, Number and Fixed14_4. +// +// t: StateVarType to check if it's a numeric type or not. +// +// Returns true if the given StateValue represents a numeric value; false +// otherwise. +func (sv StateValue) IsNumeric() bool { + return sv.valueType.IsNumeric() +} + // IsInteger checks if the state variable type is integer or not. // // It returns a boolean value indicating whether the provided StateValue @@ -11,13 +24,6 @@ func (sv StateValue) IsInteger() bool { return sv.valueType.IsInteger() } -// IsUnsignedInt checks if the state value type represents an unsigned integer. -// The method returns a boolean indicating whether the state value type is an -// unsigned integer. -func (sv StateValue) IsUnsignedInt() bool { - return sv.valueType.IsUnsignedInt() -} - // IsSignedInt checks if the state value type is a signed int. // // The return value will be a boolean indicating whether the state value type is @@ -26,6 +32,13 @@ func (sv StateValue) IsSignedInt() bool { return sv.valueType.IsSignedInt() } +// IsUnsignedInt checks if the state value type represents an unsigned integer. +// The method returns a boolean indicating whether the state value type is an +// unsigned integer. +func (sv StateValue) IsUnsignedInt() bool { + return sv.valueType.IsUnsignedInt() +} + // IsFloat returns true if the StateValue's value type represents a floating point // number; false otherwise. func (sv StateValue) IsFloat() bool { @@ -100,6 +113,17 @@ func (sv StateValue) IsTime() bool { return sv.valueType.IsTime() } +// IsUUID checks if the state value type is a UUID (Universally Unique +// Identifier). +// +// It returns true if the underlying type of the StateValue object represents a +// UUID; false otherwise. +// +// Returns: bool: Indicates whether the StateValue is of UUID type or not. +func (sv StateValue) IsUUID() bool { + return sv.valueType.IsUUID() +} + // IsURI checks if the state value type is a URI. // The method returns a boolean indicating whether the state value type represents // a Uniform Resource Identifier (URI) or not. diff --git a/upnp/statevaluetype_cmp.go b/upnp/statevaluetype_cmp.go index 35d114c8..4418b583 100644 --- a/upnp/statevaluetype_cmp.go +++ b/upnp/statevaluetype_cmp.go @@ -7,6 +7,26 @@ import ( "strings" ) +// Cmp compares two values of a given type 'StateVarType'. The comparison is +// made based on the specific type of 'a' and 'b'. It returns an integer +// indicating whether 'a' is less than, equal to, or greater than 'b'. If 'a' is +// less than 'b', it returns -1. If they are equal, it returns 0. If 'a' is +// greater than 'b', it returns 1. It also returns an error if any of the values +// can't be cast to the required type or if comparison isn't supported for the +// given type 'StateVarType'. +// +// - t: StateVarType representing the specific type to use for comparison. +// - a, b: The values to compare. They should be of type interface{} as they could be +// any valid Go type. +// +// Returns: An integer indicating the result of the comparison (-1 if 'a' is +// less than 'b', 0 if they are equal, and 1 if 'a' is greater than 'b'). It +// also returns an error if any values can't be cast or if comparison isn't +// supported for the given type. +// +// Example: +// +// result, err := t.Cmp(int32(5), int32(7)) // Returns -1 and nil error as 5 is less than 7. func (t StateVarType) Cmp(a, b interface{}) (int, error) { a, err1 := t.Cast(a) b, err2 := t.Cast(b) diff --git a/upnp/statevaluetype_typechecking.go b/upnp/statevaluetype_typechecking.go index 63b02915..d2a493ed 100644 --- a/upnp/statevaluetype_typechecking.go +++ b/upnp/statevaluetype_typechecking.go @@ -86,6 +86,12 @@ func (t StateVarType) IsFloat() bool { } } +// IsBool checks if a StateVarType is of type Boolean. It returns true if the +// StateVarType equals to StateType_Boolean, false otherwise. +func (t StateVarType) IsBool() bool { + return t == StateType_Boolean +} + // IsString reports whether or not the state variable type represents a string // value. // @@ -100,12 +106,6 @@ func (t StateVarType) IsString() bool { } } -// IsBool checks if a StateVarType is of type Boolean. It returns true if the -// StateVarType equals to StateType_Boolean, false otherwise. -func (t StateVarType) IsBool() bool { - return t == StateType_Boolean -} - // IsTime checks whether a given StateVarType is of time type or not. It accepts // a StateVarType parameter 't' and returns a boolean value based on the check. //