You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
5.8 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: comstl/util/CY_functions.h
  3. *
  4. * Purpose: CY helper functions.
  5. *
  6. * Created: 23rd August 2008
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2008-2009, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file comstl/util/CY_functions.h
  40. *
  41. * \brief [C++ only; requires COM] CY helper functions
  42. * (\ref group__library__utility__com "COM Utility" Library).
  43. */
  44. #ifndef COMSTL_INCL_COMSTL_UTIL_H_CY_FUNCTIONS
  45. #define COMSTL_INCL_COMSTL_UTIL_H_CY_FUNCTIONS
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define COMSTL_VER_COMSTL_UTIL_H_CY_FUNCTIONS_MAJOR 1
  48. # define COMSTL_VER_COMSTL_UTIL_H_CY_FUNCTIONS_MINOR 0
  49. # define COMSTL_VER_COMSTL_UTIL_H_CY_FUNCTIONS_REVISION 1
  50. # define COMSTL_VER_COMSTL_UTIL_H_CY_FUNCTIONS_EDIT 2
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Includes
  54. */
  55. #ifndef COMSTL_INCL_COMSTL_H_COMSTL
  56. # include <comstl/comstl.h>
  57. #endif /* !COMSTL_INCL_COMSTL_H_COMSTL */
  58. /* /////////////////////////////////////////////////////////////////////////
  59. * Namespace
  60. */
  61. #if !defined(_COMSTL_NO_NAMESPACE) && \
  62. !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  63. # if defined(_STLSOFT_NO_NAMESPACE)
  64. /* There is no stlsoft namespace, so must define ::comstl */
  65. namespace comstl
  66. {
  67. # else
  68. /* Define stlsoft::comstl_project */
  69. namespace stlsoft
  70. {
  71. namespace comstl_project
  72. {
  73. # endif /* _STLSOFT_NO_NAMESPACE */
  74. #endif /* !_COMSTL_NO_NAMESPACE */
  75. /* /////////////////////////////////////////////////////////////////////////
  76. * C functions
  77. */
  78. /** \brief [C only] Compares two CY structures
  79. *
  80. * \ingroup group__library__utility__com
  81. *
  82. * \param lhs Pointer to the left-hand instances to compare
  83. * \param lhs Pointer to the right-hand instances to compare
  84. *
  85. * \pre \c lhs must not be NULL.
  86. * \pre \c rhs must not be NULL.
  87. */
  88. STLSOFT_INLINE int comstl__CY_compare(CY const* lhs, CY const* rhs)
  89. {
  90. COMSTL_MESSAGE_ASSERT("Cannot pass NULL pointer(s) to CY_compare()", (NULL != lhs && NULL != rhs));
  91. if(lhs->Hi != rhs->Hi)
  92. {
  93. if(lhs->Hi < rhs->Hi)
  94. {
  95. return -1;
  96. }
  97. else
  98. {
  99. return +1;
  100. }
  101. }
  102. else
  103. {
  104. if(lhs->Lo < rhs->Lo)
  105. {
  106. return -1;
  107. }
  108. else
  109. {
  110. return +1;
  111. }
  112. }
  113. }
  114. /* /////////////////////////////////////////////////////////////////////////
  115. * Namespace
  116. */
  117. #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
  118. namespace comstl
  119. {
  120. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  121. /* /////////////////////////////////////////////////////////////////////////
  122. * C++ functions
  123. */
  124. #ifdef __cplusplus
  125. /** \brief [C++ only] Compares two CY structures
  126. *
  127. * \ingroup group__library__utility__com
  128. *
  129. * \param lhs Pointer to the left-hand instances to compare
  130. * \param lhs Pointer to the right-hand instances to compare
  131. *
  132. * \pre \c lhs must not be NULL.
  133. * \pre \c rhs must not be NULL.
  134. */
  135. inline int CY_compare(CY const* lhs, CY const* rhs)
  136. {
  137. return comstl__CY_compare(lhs, rhs);
  138. }
  139. /** \brief [C++ only] Compares two CY structures
  140. *
  141. * \ingroup group__library__utility__com
  142. *
  143. * \param lhs Reference to the left-hand instances to compare
  144. * \param lhs Reference to the right-hand instances to compare
  145. */
  146. inline int CY_compare(CY const& lhs, CY const& rhs)
  147. {
  148. return comstl__CY_compare(&lhs, &rhs);
  149. }
  150. #endif /* __cplusplus */
  151. /* /////////////////////////////////////////////////////////////////////////
  152. * Unit-testing
  153. */
  154. #ifdef STLSOFT_UNITTEST
  155. # include "./unittest/CY_functions_unittest_.h"
  156. #endif /* STLSOFT_UNITTEST */
  157. /* ////////////////////////////////////////////////////////////////////// */
  158. #ifndef _COMSTL_NO_NAMESPACE
  159. # if defined(_STLSOFT_NO_NAMESPACE) || \
  160. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  161. } /* namespace comstl */
  162. # else
  163. } /* namespace comstl_project */
  164. } /* namespace stlsoft */
  165. # endif /* _STLSOFT_NO_NAMESPACE */
  166. #endif /* !_COMSTL_NO_NAMESPACE */
  167. /* ////////////////////////////////////////////////////////////////////// */
  168. #endif /* !COMSTL_INCL_COMSTL_UTIL_H_CY_FUNCTIONS */
  169. /* ///////////////////////////// end of file //////////////////////////// */