/////////////////////////////////////////////////////////////////////////////// // 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 _BCF_UNSET_H #define _BCF_UNSET_H #include "OdaCommon.h" #include "SmartPtr.h" #define STL_USING_MAP #include "OdaSTL.h" #include "OdGUID.h" #include "OdString.h" #include "BcfConsts.h" /** \details Contains declarations related to working with BCF files content. */ namespace OdBcf { /** \details Contains declarations related to utilities related to working with BCF files content. */ namespace Utils { /** \details A template function that returns an undefined value for those BCF datatypes that do not have an implemented getUnset() function. \returns An undefined (unset) value. */ template const TUnsetable& getUnset() { ODA_ASSERT(0 && "Unknown type. Add getUnset for it."); static TUnsetable unsettled = 0; return unsettled; } /** \details A template function that returns an undefined value for the double datatype. \returns A double value that represents an unset value. */ template <> inline const double& getUnset() { return Consts::OdNan; } /** \details A template function that returns an undefined value for the long datatype. \returns A long value that represents an unset value. */ template <> inline const long& getUnset() { return Consts::OdLongUnset; } /** \details A template function that returns an undefined value for the int datatype. \returns An int value that represents an unset value. */ template <> inline const int& getUnset() { return Consts::OdIntUnset; } /** \details A template function that returns an undefined value for the OdString datatype. \returns OdString value that represents an unset value. */ template <> inline const OdString& getUnset() { static OdString stringUnset = Consts::OdAnsiStringUnset; return stringUnset; } /** \details A template function that returns an undefined value for the OdAnsiString datatype. \returns OdAnsiString value that represents an unset value. */ template <> inline const OdAnsiString& getUnset() { static OdAnsiString stringUnset = Consts::OdAnsiStringUnset; return stringUnset; } /** \details A template function that returns an undefined value for the OdGUID datatype. \returns OdGUID value that represents an unset value. */ template <> inline const OdGUID& getUnset() { return OdGUID::kNull; } /** \details A function that defines whether a specified boolean value is not set (undefined). \returns true if the value is not set; otherwise, the function returns false. */ inline bool isUnset(const bool & value) { return false; } /** \details A function that defines whether a specified float value is not set (undefined). \returns true if the value is not set; otherwise, the function returns false. */ inline bool isUnset(const float & value) { return value != value; } /** \details A function that defines whether a specified double value is not set (undefined). \returns true if the value is not set; otherwise, the function returns false. */ inline bool isUnset(const double & value) { return value != value; } /** \details A function that defines whether a specified long value is not set (undefined). \returns true if the value is not set; otherwise, the function returns false. */ inline bool isUnset(const long value) { return value == Consts::OdLongUnset; } /** \details A function that defines whether a specified unsigned integer value is not set (undefined). \returns true if the value is not set; otherwise, the function returns false. */ inline bool isUnset(const int value) { return value == Consts::OdIntUnset; } /** \details A function that defines whether a specified OdString value is not set (undefined). \param value [in] Value to check. \returns true if the value is not set; otherwise, the function returns false. */ inline bool isUnset(const OdString & value) { return value.getLength() == Consts::OdAnsiStringUnsetLength && value.compare(Consts::OdAnsiStringUnset) == 0; } /** \details A function that defines whether a specified OdAnsiString value is not set (undefined). \param value [in] Value to check. \returns true if the value is not set; otherwise, the function returns false. */ inline bool isUnset(const OdAnsiString & value) { return value.getLength() == Consts::OdAnsiStringUnsetLength && value.compare(Consts::OdAnsiStringUnset) == 0; } /** \details A function that defines whether a string value, represented as a null-terminated array of chars, is not set (undefined). \param value [in] Value to check. \returns true if the value is not set; otherwise, the function returns false. */ inline bool isUnset(const char * value) { return strlen(value) == Consts::OdAnsiStringUnsetLength && strcmp(value, Consts::OdAnsiStringUnset) == 0; } /** \details A function that defines whether a specified OdGUID value is not set (undefined). \param value [in] Value to check. \returns true if the value is not set; otherwise, the function returns false. */ inline bool isUnset(const OdGUID & value) { return value == OdGUID::kNull; } /** \details A function that defines whether a smart pointer is not set (undefined). \param value [in] Value to check. \returns true if the smart pointer is not set; otherwise, the function returns false. */ template inline bool isUnset(const OdSmartPtr & value) { return value.isNull(); } /** \details A function that defines whether an array of smart pointers is not set (undefined). \param value [in] Value to check. \returns true if the array of smart pointers is not set; otherwise, the function returns false. */ template inline bool isUnset(const OdArray & value) { return value.empty(); } /** \details A function that defines whether an STL map object is not set (undefined). \param value [in] Value to check. \returns true if the map is not set; otherwise, the function returns false. */ template inline bool isUnset(const std::map & value) { return value.empty(); } /** \details A function that initializes a passed value as an unset (undefined) one. \param value [out] A placeholder for the value to be initialized. */ template void initUnset(TUnsetable &value) { value = getUnset(); } } } #endif // _BCF_UNSET_H