///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
// All rights reserved.
//
// This software and its documentation and related materials are owned by
// the Alliance. The software may only be incorporated into application
// programs owned by members of the Alliance, subject to a signed
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable
// trade secrets of the Alliance and its suppliers. The software is also
// protected by copyright law and international treaty provisions. Application
// programs incorporating this software must include the following statement
// with their copyright notices:
//
// This application incorporates Open Design Alliance software pursuant to a license
// agreement with Open Design Alliance.
// Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
// All rights reserved.
//
// By use of this software, its documentation or related materials, you
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
#ifndef _DAI_PRIMITIVE_H_
#define _DAI_PRIMITIVE_H_
#include "OdAnsiString.h"
#include "daiConsts.h"
#include "daiUtils/daiUnset.h"
#include "daiFixedLengthString.h"
#include "daiTCKind.h"
#include "SharedPtr.h"
#include "TD_PackPush.h"
/** \details
Implements the Data Access Interface (DAI) that provides functionality for manipulating data that is defined within the EXPRESS SCHEMA format.
*/
namespace OdDAI {
class DAI_EXPORT Logical;
class NamedType;
/** \details
Defines values for the data type.
*/
enum Boolean_ {
/**False value.*/
kBoolean_F,
/**True value.*/
kBoolean_T,
/**The value is unset.*/
kBoolean_unset
};
/** \details
A class that represents the SDAI primitive Boolean data type.
*/
class DAI_EXPORT Boolean {
Boolean_ m_val;
public:
/**A constant that implements the False value for the data type.*/
DAI_EXPORT_STATIC static const Boolean False;
/**A constant that implements the True value for the data type.*/
DAI_EXPORT_STATIC static const Boolean True;
/**A constant that implements the unset value for the data type.*/
DAI_EXPORT_STATIC static const Boolean Unset;
/** \details
Creates a new Boolean object with an unset value.
*/
Boolean() : m_val(kBoolean_unset) {};
/** \details
Creates a new Boolean object as a copy of another existing Boolean value
(copy constructor for the class).
\param other [in] Another instance of the class that will be copied.
*/
Boolean(const Boolean &other) : m_val(other.m_val) {};
/** \details
Creates a new Boolean object with a specified value.
\param val [in] An initial value of the created Boolean object.
*/
Boolean(Boolean_ val) : m_val(val) {};
/** \details
Creates a new Boolean object with a specified value contained in a object.
\param logical [in] A object that contains the initial value for the created Boolean object.
*/
Boolean(const Logical &logical);
/** \details
Checks whether the Boolean object has a defined value (whether the value is set).
\returns 1 if the Boolean object's value is defined (set); otherwise, the method returns 0.
\sa
method.
*/
int exists() const { return m_val != kBoolean_unset ? 1 : 0; };
/** \details
Flashes the Boolean object to the unset value.
After calling this method the method returns 0.
\sa
method.
*/
void nullify() { m_val = kBoolean_unset; };
/** \details
Casts the Boolean object's value to the signed int data type.
*/
operator int() const { return m_val; };
/*operator Logical() const {
if (m_val == kBoolean_F)
return Logical::False;
if (m_val == kBoolean_T)
return Logical::True;
return Logical::Unset;
};*/
/** \details
Assignment operator for the Boolean data type.
The operator casts specified value of the to the Logical value and assigns it to the object.
\param val [in] An value to be assigned (a right-hand operand of the assignment operation).
\returns The reference to the Boolean object modified by the assignment operation.
*/
Boolean& operator = (const Boolean_ val) { m_val = val; return *this; };
/** \details
Assignment operator for the Boolean data type.
The operator casts specified signed long value to the Boolean value and assigns it to the object.
\param val [in] A signed long data type value to be assigned (a right-hand operand of the assignment operation).
\returns The reference to the Boolean object modified by the assignment operation.
*/
Boolean& operator = (const long val) { m_val = (Boolean_)val; return *this; };
/** \details
Assignment operator for the Boolean data type.
The operator casts specified ANSI string
to the Boolean value and assigns it to the object.
\param val [in] An ANSI string to be assigned (a right-hand operand of the assignment operation).
\returns The reference to the Boolean object modified by the assignment operation.
\remarks
The specified ANSI string should be:
* "F" to set the Boolean object to the False value.
* "T" to set the Boolean object to the True value.
In all other cases, the operator makes the Boolean object unset.
*/
Boolean& operator = (const OdAnsiString &val) {
if (val == "F")
m_val = kBoolean_F;
else
if (val == "T")
m_val = kBoolean_T;
else
m_val = kBoolean_unset;
return *this;
};
/** \details
Operator that implements the logical OR operation (C++ "||" operator) for the Boolean data type.
\param other [in] Another Boolean value (right-hand of the logical AND operation).
\returns A Boolean value that is the result of the operation.
*/
Boolean operator || (const Boolean &other)
{
if (m_val == True || other.m_val == True)
return OdDAI::Boolean::True;
return OdDAI::Boolean::False;
}
/** \details
Operator that implements the logical AND operation (C++ "&&" operator) for the Boolean data type.
\param other [in] Another Boolean value (right-hand of the logical AND operation).
\returns A Boolean value that is the result of the operation.
*/
Boolean operator && (const Boolean &other)
{
if (m_val == True && other.m_val == True)
return OdDAI::Boolean::True;
return OdDAI::Boolean::False;
}
/** \details
Converts the Boolean object value into an ANSI string.
\returns An ANSI string that matches the Boolean object value.
*/
const OdAnsiString& toStr() {
switch (m_val)
{
case kBoolean_F:
return OdDAI::Consts::StringF;
case kBoolean_T:
return OdDAI::Consts::StringT;
default:
break;
}
return OdDAI::Consts::AnsiStringUnset;
};
};
/** \details
Defines values for the data type.
*/
enum Logical_ {
/**False value.*/
kLogical_F,
/**True value.*/
kLogical_T,
/**The value is unknown.*/
kLogical_U,
/**The value is unset.*/
kLogical_unset
};
/** \details
A class that represents the SDAI primitive Logical data type.
*/
class DAI_EXPORT Logical {
Logical_ m_val;
public:
/**A constant that implements the False value for the data type.*/
DAI_EXPORT_STATIC static const Logical False;
/**A constant that implements the True value for the data type.*/
DAI_EXPORT_STATIC static const Logical True;
/**A constant that implements the value Unknown for the data type.*/
DAI_EXPORT_STATIC static const Logical Unknown;
/**A constant that implements the unset value for the data type.*/
DAI_EXPORT_STATIC static const Logical Unset;
/** \details
Creates a new Logical object with an unset value.
*/
Logical() : m_val(kLogical_unset) {};
/** \details
Creates a new Logical object with a specified value.
\param val [in] An initial value of the created Logical object.
*/
Logical(Logical_ val) : m_val(val) {};
/** \details
Creates a new Logical object as a copy of another existing Logical value
(copy constructor for the class).
\param other [in] Another instance of the class that will be copied.
*/
Logical(const Logical &other) : m_val(other.m_val) {};
/** \details
Creates a new Logical object with a specified signed int value.
\param i [in] A signed int value to be cast into a value of the created Logical object.
*/
Logical(int i) {
if (i >= 0 && i < 4)
m_val = (Logical_)i;
else
m_val = kLogical_unset;
}
/** \details
Creates a new Logical object with a specified value contained in a object.
\param boo [in] A object that contains the initial value for the created Logical object.
*/
Logical(const Boolean &boo)
{
if (boo.exists())
m_val = (boo == Boolean::True ? kLogical_T : kLogical_F);
else
m_val = kLogical_unset;
};
/** \details
Checks whether the Logical object has a defined value (whether the value is set).
\returns 1 if the Logical object's value is defined (set); otherwise, the method returns 0.
\sa
method.
*/
int exists() const { return m_val != kLogical_unset ? 1 : 0; };
/** \details
Flashes the Logical object to the unset value.
After calling this method the method returns 0.
\sa
method.
*/
void nullify() { m_val = kLogical_unset; };
/** \details
Casts the Logical object's value to the value of the enumeration value.
*/
operator Logical_() const { return m_val; };
//operator int() const { return m_val; };
/** \details
Assignment operator for the Logical data type.
The operator casts specified value of the to the Logical value and assigns it to the object.
\param val [in] An value to be assigned (a right-hand operand of the assignment operation).
\returns The reference to the Logical object modified by the assignment operation.
*/
Logical& operator = (const Logical_ val) { m_val = val; return *this; };
/** \details
Assignment operator for the Logical data type.
The operator casts specified signed long value to the Logical value and assigns it to the object.
\param val [in] A signed long data type value to be assigned (a right-hand operand of the assignment operation).
\returns The reference to the Logical object modified by the assignment operation.
*/
Logical& operator = (const long val) { m_val = (Logical_)val; return *this; };
/** \details
Assignment operator for the Logical data type.
The operator casts specified ANSI string
to the Logical value and assigns it to the object.
\param val [in] An ANSI string to be assigned (a right-hand operand of the assignment operation).
\returns The reference to the Logical object modified by the assignment operation.
\remarks
The specified ANSI string should be:
* "F" to set the Logical object to the False value.
* "T" to set the Logical object to the True value.
* "U" to set the Logical object to the Unknown value.
In all other cases, the operator makes the Logical object unset.
*/
Logical& operator = (const OdAnsiString &val) {
if (val == "F")
m_val = kLogical_F;
else
if (val == "T")
m_val = kLogical_T;
else
if (val == "U")
m_val = kLogical_U;
else
m_val = kLogical_unset;
return *this;
};
/** \details
An equality operator for the Logical data type.
\param other [in] Another Logical object to be compared with (the right-hand operand of the comparison operation).
\returns true if Logical objects are equal; otherwise, the method returns false.
*/
bool operator == (const Logical &other) const
{
return m_val == other.m_val;
};
/** \details
A non-equality operator for the Logical data type.
\param other [in] Another Logical object to be compared with (the right-hand operand of the comparison operation).
\returns true if Logical objects are NOT equal; otherwise, the method returns false.
*/
bool operator != (const Logical& other) const
{
return !operator == (other);
};
/** \details
A negation ("NOT") operator for the Logical data type.
Inverts the Logical object value:
* from True into False.
* from False into True
* in all other cases the operator returns the Unknown value.
\returns The Logical object that has the inverted value.
\remarks
Implementation according to the ISO 10303-11, 12.4.1.
*/
Logical operator ! () const
{
if (m_val == kLogical_F)
return kLogical_T;
if (m_val == kLogical_T)
return kLogical_F;
return kLogical_U;
};
/** \details
An intersection ("AND") operator for the Logical data type.
\param other [in] Another Logical object (right-handed operand of the "AND" operation).
\returns The resulted Logical object.
\remarks
Implementation according to the ISO 10303-11, 12.4.2.
*/
Logical operator && (const Logical &other)
{
if (m_val == kLogical_unset || other.m_val == kLogical_unset)
return kLogical_U;
if (m_val == kLogical_T)
return other;
if (m_val == kLogical_U)
{
if (other.m_val == kLogical_F)
return other;
return kLogical_U;
}
return kLogical_F;
}
/** \details
A union ("OR") operator for the Logical data type.
\param other [in] Another Logical object (right-handed operand of the "OR" operation).
\returns The resulted Logical object.
\remarks
Implementation according to the ISO 10303-11, 12.4.3.
*/
Logical operator || (const Logical &other)
{
if (m_val == kLogical_unset || other.m_val == kLogical_unset)
return kLogical_U;
if (m_val == kLogical_T)
return kLogical_T;
if (m_val == kLogical_U)
{
if (other.m_val == kLogical_T)
return kLogical_T;
return kLogical_U;
}
return other.m_val;
}
/** \details
A "XOR" operator for the Logical data type.
\param other [in] Another Logical object (right-handed operand of the "OR" operation).
\returns The resulted Logical object.
\remarks
Implementation according to the ISO 10303-11, 12.4.4.
*/
Logical operator ^ (const Logical &other)
{
if (m_val == kLogical_U || m_val == kLogical_unset ||
other.m_val == kLogical_U || other.m_val == kLogical_unset)
return kLogical_U;
if (m_val == other.m_val)
return kLogical_F;
return kLogical_T;
}
/** \details
Casts the Logical object's value to an ANSI string.
*/
operator OdAnsiString ()
{
switch (m_val)
{
case kLogical_F:
return "F";
case kLogical_T:
return "T";
case kLogical_U:
return "U";
default:
break;
}
return OdDAI::Consts::OdAnsiStringUnset;
};
};
/** \details
A class that represents the SDAI primitive Number data type.
*/
class DAI_EXPORT Number
{
public:
/**An unset value of the primitive Number data type.*/
DAI_EXPORT_STATIC static const Number Unset;
/** \details
Creates a new Number object with the default value.
*/
Number();
/** \details
Creates a new Number object with a specified value contained in a object.
\param initValue [in] A object that contains the initial value for the created Number object.
*/
explicit Number(int initValue);
/** \details
Creates a new Number object with a specified value contained in a object.
\param initValue [in] A object that contains the initial value for the created Number object.
*/
explicit Number(double initValue);
/** \details
Creates a new Number object as a copy of another existing Number value
(copy constructor for the class).
\param copyFrom [in] Another instance of the class that will be copied.
*/
Number(const Number& copyFrom);
/** \details
Assignment operator for the Number data type.
\param applyFrom [in] A Number data type value to be assigned (a right-hand operand of the assignment operation).
\returns The reference to the Number object modified by the assignment operation.
*/
Number& operator= (const Number& applyFrom);
/** \details
Assignment operator for the double data type.
The operator casts specified double value to the Number value and assigns it to the object.
\param applyFrom [in] A double data type value to be assigned (a right-hand operand of the assignment operation).
\returns The reference to the Number object modified by the assignment operation.
*/
Number& operator= (const double& applyFrom);
/** \details
Assignment operator for the int data type.
The operator casts specified int value to the Number value and assigns it to the object.
\param applyFrom [in] A int data type value to be assigned (a right-hand operand of the assignment operation).
\returns The reference to the Number object modified by the assignment operation.
*/
Number& operator= (const int& applyFrom);
/** \details
Less than operator for the Number data type.
\param compareTo [in] Another Number object to be compared with (the right-hand operand of the comparison operation).
\returns true if Number objects are less; otherwise, the method returns false.
*/
bool operator< (const Number& compareTo) const;
/** \details
Not equal operator for the Number data type.
\param compareTo [in] Another Number object to be compared with (the right-hand operand of the comparison operation).
\returns true if Number objects are not equal; otherwise, the method returns false.
*/
bool operator!= (const Number& compareTo) const;
/** \details
An equality operator for the Number data type.
\param compareTo [in] Another Number object to be compared with (the right-hand operand of the comparison operation).
\returns true if Number objects are equal; otherwise, the method returns false.
*/
bool operator== (const Number& compareTo) const;
/** \details
An equality operator for the Number data type.
\param compareTo [in] Another Number object to be compared with (the right-hand operand of the comparison operation).
\returns true if Number objects are equal; otherwise, the method returns false.
*/
bool operator== (const int& compareTo) const;
/** \details
An equality operator for the Number data type.
\param compareTo [in] Another Number object to be compared with (the right-hand operand of the comparison operation).
\returns true if Number objects are equal; otherwise, the method returns false.
*/
bool operator== (const double& compareTo) const;
/** \details
operator int for the Number data type.
\returns integer value if it placed at Number; otherwise, the method throw the exception.
*/
operator int() const;
/** \details
operator double for the Number data type.
\returns double value if it placed at Number; otherwise, the method throw the exception.
*/
operator double() const;
/** \details
Provides OdTCKind of the number.
\returns kind of the number.
*/
OdTCKind kind() const;
/** \details
Provides the name of the current value type for Number.
\returns name of the settled value. If value is not set the function should returns empty string.
*/
const OdAnsiString& underlyingTypeName() const;
/** \details
Sets the name of the underlying type for the Number object.
\param typeName [in] An ANSI string that contains the type name to be set.
\returns true if the underlying type was changed; otherwise, the method return false.
*/
bool underlyingTypeName(const OdAnsiString& typeName);
/** \details
Sets the underlying type for the current value.
\param newType [in] A raw pointer to the object that contains the new underlying type.
\returns true if underlying type was changed, otherwise return false.
*/
bool setUnderlyingType(const NamedType* newType);
/** \details
Provides current value type for Number.
\returns the named type of settled value. If value is not set the function should returns nullptr.
*/
const NamedType* getUnderlyingType() const;
/** \details
Reset Number to unset state
*/
void nullify();
/** \details
Shows the current status of the value.
\returns true if Number is not empty; otherwise return false.
*/
bool exists() const;
/** \details
Provides integer type for Number.
\returns integer value if it placed at Number; otherwise, the method throw the exception.
\remarks
if Number does not integer exception should be thrown.
*/
int getInteger() const;
/** \details
Sets integer type for Number.
\param setFrom [in] new integer value for Number.
*/
void setInteger(int setFrom);
/** \details
Provides double type for Number.
\returns double value if it placed at Number; otherwise, the method throw the exception.
\remarks
if Number does not real exception should be thrown.
*/
double getReal() const;
/** \details
Sets double type for Number.
\param setFrom [in] new double value for Number.
*/
void setReal(const double& setFrom);
/** \details
Gets integer value from Number.
\param getTo [out] integer value.
\returns true if Number value type is integer, otherwise returns false
*/
bool tryGetInteger(int& getTo) const;
/** \details
Gets double value from Number.
\param getTo [out] double value.
\returns true if Number value type is double, otherwise returns false
*/
bool tryGetReal(double& getTo) const;
/** \details
Verifying if Number is integer.
\returns true if Number value type is integer, otherwise returns false
*/
bool isInteger() const;
/** \details
Verifying if Number is double.
\returns true if Number value type is double, otherwise returns false
*/
bool isReal() const;
protected:
inline void copyByState(const Number& other);
private:
const OdDAI::NamedType* m_underlyingType = nullptr;
union {
int m_int;
double m_dbl;
};
};
/** \details
A data type that represents a smart pointer to an value.
*/
typedef OdSharedPtr NumberPtr;
/** \details
A data type that represents the SDAI primitive BINARY type.
*/
typedef OdAnsiString BINARY;
/** \details
A structure that contains information about the enumeration value.
*/
struct EnumValueInfo
{
/**An array of bytes.*/
const char* value;
};
/** \details
Contains useful set of functions to operate with values of primitive DAI types.
*/
namespace Utils
{
/** \details
Retrieves the unset value of the data type.
\returns The unset value of the data type.
*/
template <> inline const OdDAI::Logical& getUnset() { return OdDAI::Logical::Unset; }
/** \details
Retrieves the unset value of the data type.
\returns The unset value of the data type.
*/
template <> inline const OdDAI::Boolean& getUnset() { return OdDAI::Boolean::Unset; }
/** \details
Retrieves the unset value of the data type.
\returns The unset value of the data type.
*/
template <> inline const OdDAI::Number& getUnset() { return OdDAI::Number::Unset; }
/** \details
Retrieves the unset value of the data type.
\returns The unset value of the data type.
*/
template <> inline const OdDAI::Logical_& getUnset() { static OdDAI::Logical_ temp = OdDAI::kLogical_unset; return temp; }
/** \details
Retrieves the unset value of the data type.
\returns The unset value of the data type.
*/
template <> inline const OdDAI::Boolean_& getUnset() { static OdDAI::Boolean_ temp = OdDAI::kBoolean_unset; return temp; }
/** \details
Retrieves whether a specified instance of the class has an unset value (the value is not set).
\param value [in] The object to check.
\returns true if the object has an unset value; otherwise, the function returns false.
*/
inline bool isUnset(const OdDAI::Logical_& value) { return value == getUnset(); }
/** \details
Retrieves whether a specified instance of the class has an unset value (the value is not set).
\param value [in] The object to check.
\returns true if the object has an unset value; otherwise, the function returns false.
*/
inline bool isUnset(const OdDAI::Boolean_& value) { return value == getUnset(); }
/** \details
Retrieves whether a specified instance of the class has an unset value (the value is not set).
\param value [in] The object to check.
\returns true if the object has an unset value; otherwise, the function returns false.
*/
inline bool isUnset(const OdDAI::Number& value) { return value == getUnset(); }
/** \details
Retrieves whether a specified instance of the class has an unset value (the value is not set).
\param value [in] A raw pointer to the object to check.
\returns true if the object has an unset value; otherwise, the function returns false.
*/
inline bool isUnset(const OdDAI::Number* value) { return (value == nullptr || *value == getUnset()); }
/** \details
Retrieves whether a specified instance of the class has an unset value (the value is not set).
\param value [in] A raw pointer to the object to check.
\returns true if the object has an unset value; otherwise, the function returns false.
*/
inline bool isUnset(const OdDAI::Logical& value) { return value == getUnset(); }
/** \details
Retrieves whether a specified instance of the class has an unset value (the value is not set).
\param value [in] A raw pointer to the object to check.
\returns true if the object has an unset value; otherwise, the function returns false.
*/
inline bool isUnset(const OdDAI::Boolean& value) { return value == getUnset(); }
}
}
#include "TD_PackPop.h"
#endif // _DAI_PRIMITIVE_H_