vector.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Libgearman library
  4. *
  5. * Copyright (C) 2011 Data Differential, http://datadifferential.com/
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are
  9. * met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * * Redistributions in binary form must reproduce the above
  15. * copyright notice, this list of conditions and the following disclaimer
  16. * in the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * * The names of its contributors may not be used to endorse or
  20. * promote products derived from this software without specific prior
  21. * written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  27. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  28. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  29. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  30. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. */
  36. #pragma once
  37. /**
  38. vectors are always under our control so we make some assumptions about them.
  39. 1) is_initialized is always valid.
  40. 2) A string once intialized will always be, until free where we
  41. unset this flag.
  42. */
  43. struct gearman_vector_st {
  44. char *end;
  45. char *string;
  46. size_t current_size;
  47. struct {
  48. bool is_allocated:1;
  49. } options;
  50. };
  51. GEARMAN_LOCAL
  52. gearman_vector_st *gearman_string_create(gearman_vector_st *string,
  53. size_t initial_size);
  54. GEARMAN_LOCAL
  55. gearman_vector_st *gearman_string_create(gearman_vector_st *self, const char *str, size_t initial_size);
  56. #ifdef __cplusplus
  57. extern "C" {
  58. #endif
  59. GEARMAN_LOCAL
  60. gearman_vector_st *gearman_string_clone(const gearman_vector_st *);
  61. GEARMAN_LOCAL
  62. gearman_return_t gearman_string_check(gearman_vector_st *string, size_t need);
  63. GEARMAN_LOCAL
  64. char *gearman_string_c_copy(gearman_vector_st *string);
  65. GEARMAN_LOCAL
  66. gearman_return_t gearman_string_append_character(gearman_vector_st *string,
  67. char character);
  68. GEARMAN_LOCAL
  69. gearman_return_t gearman_string_append(gearman_vector_st *string,
  70. const char *value, size_t length);
  71. GEARMAN_LOCAL
  72. void gearman_string_reset(gearman_vector_st *string);
  73. GEARMAN_LOCAL
  74. void gearman_string_free(gearman_vector_st *string);
  75. GEARMAN_LOCAL
  76. size_t gearman_string_length(const gearman_vector_st *self);
  77. GEARMAN_LOCAL
  78. const char *gearman_string_value(const gearman_vector_st *self);
  79. GEARMAN_LOCAL
  80. char *gearman_string_value_mutable(const gearman_vector_st *self);
  81. GEARMAN_LOCAL
  82. gearman_string_t gearman_string(const gearman_vector_st *self);
  83. GEARMAN_LOCAL
  84. gearman_string_t gearman_string_take_string(gearman_vector_st *self);
  85. #ifdef __cplusplus
  86. }
  87. #endif