The source code and dockerfile for the GSW2024 AI Lab.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

162 lines
5.3 KiB

2 months ago
  1. /**
  2. @file
  3. @ingroup cstringstream
  4. @brief Package for simple stringstreams in C.
  5. @author Fabio Somenzi
  6. @copyright@parblock
  7. Copyright (c) 2014-2015, Regents of the University of Colorado
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions
  11. are met:
  12. Redistributions of source code must retain the above copyright
  13. notice, this list of conditions and the following disclaimer.
  14. Redistributions in binary form must reproduce the above copyright
  15. notice, this list of conditions and the following disclaimer in the
  16. documentation and/or other materials provided with the distribution.
  17. Neither the name of the University of Colorado nor the names of its
  18. contributors may be used to endorse or promote products derived from
  19. this software without specific prior written permission.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24. COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  30. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. POSSIBILITY OF SUCH DAMAGE.
  32. @endparblock
  33. $Id: cstringstream.h,v 1.1 2015/07/01 20:36:47 fabio Exp fabio $
  34. */
  35. #ifndef CSTRINGSTREAM_H_
  36. #define CSTRINGSTREAM_H_
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /*---------------------------------------------------------------------------*/
  41. /* Type declarations */
  42. /*---------------------------------------------------------------------------*/
  43. /**
  44. * @brief Type of a string stream.
  45. */
  46. typedef struct _cstringstream * cstringstream;
  47. /**
  48. * @brief Const-qualified version of cstringstream.
  49. */
  50. typedef struct _cstringstream const * const_cstringstream;
  51. /*---------------------------------------------------------------------------*/
  52. /* Function prototypes */
  53. /*---------------------------------------------------------------------------*/
  54. /**
  55. * @brief Returns a new cstringstream with an empty string.
  56. * @return NULL if creation fails.
  57. */
  58. cstringstream newStringStream(void);
  59. /**
  60. * @brief Frees cstringstream ss.
  61. */
  62. void deleteStringStream(cstringstream ss);
  63. /**
  64. * @brief Clears the contents of cstringstream ss.
  65. * @return 0 if succesful and -1 if ss is an invalid pointer.
  66. */
  67. int clearStringStream(cstringstream ss);
  68. /**
  69. * @brief Copies cstringstream src to a new cstringstream.
  70. * @return 0 if succesful or -1 if src is an invalid pointer
  71. * or memory allocation fails.
  72. */
  73. cstringstream copyStringStream(const_cstringstream src);
  74. /**
  75. * @brief Changes the size of cstringstream ss.
  76. * @return 0 if successful or -1 if resizing fails.
  77. */
  78. int resizeStringStream(cstringstream ss, size_t newSize);
  79. /**
  80. * @brief Writes the size of cstringstream ss to the location pointed by num.
  81. * @return 0 if succesful or -1 if ss is an invalid pointer.
  82. */
  83. int sizeStringStream(const_cstringstream ss, size_t * num);
  84. /**
  85. * @brief Writes the i-th element of cstringstream ss to the location
  86. * pointed by c.
  87. * @return 0 if successful or -1 otherwise.
  88. */
  89. int getStringStream(const_cstringstream ss, size_t i, char * c);
  90. /**
  91. * @brief Adds char c at the end of cstringstream ss.
  92. * @return 0 if successful or -1 otherwise.
  93. */
  94. int appendCharStringStream(cstringstream ss, char c);
  95. /**
  96. * @brief Adds string s at the end of cstringstream ss.
  97. * @return 0 if successful or -1 otherwise.
  98. */
  99. int appendStringStringStream(cstringstream ss, char const * s);
  100. /**
  101. * @brief Adds int d at the end of cstringstream ss.
  102. * @return 0 if successful or -1 otherwise.
  103. */
  104. int appendIntStringStream(cstringstream ss, int d);
  105. /**
  106. * @brief Adds unsigned u at the end of cstringstream ss.
  107. * @return 0 if successful or -1 otherwise.
  108. */
  109. int appendUnsignedStringStream(cstringstream ss, unsigned u);
  110. /**
  111. * @brief Adds long ld at the end of cstringstream ss.
  112. * @return 0 if successful or -1 otherwise.
  113. */
  114. int appendLongStringStream(cstringstream ss, long ld);
  115. /**
  116. * @brief Adds unsigned long lu at the end of cstringstream ss.
  117. * @return 0 if successful or -1 otherwise.
  118. */
  119. int appendUnsignedLongStringStream(cstringstream ss, unsigned long lu);
  120. /**
  121. * @brief Adds double g at the end of cstringstream ss.
  122. * @return 0 if successful or -1 otherwise.
  123. */
  124. int appendDoubleStringStream(cstringstream ss, double g);
  125. /**
  126. * @brief Sets the i-th element of cstringstream ss to c.
  127. * @return 0 if successful or -1 otherwise.
  128. *
  129. * The i-th element of ss must already exist.
  130. */
  131. int putStringStream(cstringstream ss, size_t index, char c);
  132. /**
  133. * @brief Returns a NULL-terminated string from the contents of
  134. * cstringstream ss.
  135. * @details In case of failure, it returns NULL.
  136. * The returned string must be freed by the caller.
  137. */
  138. char * stringFromStringStream(const_cstringstream ss);
  139. #ifdef __cplusplus
  140. }
  141. #endif
  142. #endif