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.

184 lines
5.5 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: comstl/util/stream_functions.h
  3. *
  4. * Purpose: Stream functions.
  5. *
  6. * Created: 22nd October 2005
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2005-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/stream_functions.h
  40. *
  41. * \brief [C++ only; requires COM] COM stream functions
  42. * (\ref group__library__utility__com "COM Utility" Library).
  43. */
  44. #ifndef COMSTL_INCL_COMSTL_UTIL_H_STREAM_FUNCTIONS
  45. #define COMSTL_INCL_COMSTL_UTIL_H_STREAM_FUNCTIONS
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define COMSTL_VER_COMSTL_UTIL_H_STREAM_FUNCTIONS_MAJOR 2
  48. # define COMSTL_VER_COMSTL_UTIL_H_STREAM_FUNCTIONS_MINOR 1
  49. # define COMSTL_VER_COMSTL_UTIL_H_STREAM_FUNCTIONS_REVISION 3
  50. # define COMSTL_VER_COMSTL_UTIL_H_STREAM_FUNCTIONS_EDIT 15
  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] Gets the size of a stream
  79. *
  80. * \ingroup group__library__utility__com
  81. *
  82. * \see comstl::get_stream_size
  83. */
  84. STLSOFT_INLINE HRESULT comstl__get_stream_size(LPSTREAM pstm, ULARGE_INTEGER *psize)
  85. {
  86. STATSTG statstg;
  87. HRESULT hr = COMSTL_ITF_CALL(pstm)->Stat(COMSTL_ITF_THIS(pstm) &statstg, STATFLAG_NONAME);
  88. if(SUCCEEDED(hr))
  89. {
  90. *psize = statstg.cbSize;
  91. }
  92. return hr;
  93. }
  94. /* /////////////////////////////////////////////////////////////////////////
  95. * Namespace
  96. */
  97. #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
  98. namespace comstl
  99. {
  100. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  101. /* /////////////////////////////////////////////////////////////////////////
  102. * C++ functions
  103. */
  104. #ifdef __cplusplus
  105. /** \brief Gets the size of a stream
  106. *
  107. * \ingroup group__library__utility__com
  108. */
  109. inline HRESULT get_stream_size(LPSTREAM pstm, ULARGE_INTEGER *psize)
  110. {
  111. return comstl__get_stream_size(pstm, psize);
  112. }
  113. /** \brief Gets the size of a stream
  114. *
  115. * \ingroup group__library__utility__com
  116. */
  117. inline HRESULT get_stream_size(LPSTREAM pstm, ULARGE_INTEGER &size)
  118. {
  119. return comstl__get_stream_size(pstm, &size);
  120. }
  121. /** \brief Gets the size of a stream
  122. *
  123. * \ingroup group__library__utility__com
  124. */
  125. inline HRESULT get_stream_size(LPSTREAM pstm, cs_uint64_t &size)
  126. {
  127. ULARGE_INTEGER uli;
  128. HRESULT hr = comstl__get_stream_size(pstm, &uli);
  129. if(SUCCEEDED(hr))
  130. {
  131. size = uli.QuadPart;
  132. }
  133. return hr;
  134. }
  135. #endif /* __cplusplus */
  136. /* /////////////////////////////////////////////////////////////////////////
  137. * Unit-testing
  138. */
  139. #ifdef STLSOFT_UNITTEST
  140. # include "./unittest/stream_functions_unittest_.h"
  141. #endif /* STLSOFT_UNITTEST */
  142. /* ////////////////////////////////////////////////////////////////////// */
  143. #ifndef _COMSTL_NO_NAMESPACE
  144. # if defined(_STLSOFT_NO_NAMESPACE) || \
  145. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  146. } /* namespace comstl */
  147. # else
  148. } /* namespace comstl_project */
  149. } /* namespace stlsoft */
  150. # endif /* _STLSOFT_NO_NAMESPACE */
  151. #endif /* !_COMSTL_NO_NAMESPACE */
  152. /* ////////////////////////////////////////////////////////////////////// */
  153. #endif /* !COMSTL_INCL_COMSTL_UTIL_H_STREAM_FUNCTIONS */
  154. /* ///////////////////////////// end of file //////////////////////////// */