Categories_and_Strings.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Categories_and_Strings.cpp
  2. *
  3. * Copyright (C) 1993-2017 David Weenink
  4. *
  5. * This code is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This code is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /*
  19. djmw 20020315 GPL header
  20. djmw 20110304 Thing_new
  21. */
  22. #include "Categories_and_Strings.h"
  23. autoStrings Categories_to_Strings (Categories me) {
  24. try {
  25. Melder_require (my size > 0, U"There should be at least one category present.");
  26. autoStrings thee = Thing_new (Strings);
  27. thy strings = autostring32vector (my size);
  28. thy numberOfStrings = my size;
  29. for (integer i = 1; i <= my size; i ++) {
  30. SimpleString s = my at [i];
  31. thy strings [i] = Melder_dup (s -> string.get());
  32. }
  33. return thee;
  34. } catch (MelderError) {
  35. Melder_throw (me, U": not converted to Strings.");
  36. }
  37. }
  38. autoCategories Strings_to_Categories (Strings me) {
  39. try {
  40. Melder_require (my numberOfStrings > 0, U"Empty strings.");
  41. autoCategories thee = Thing_new (Categories);
  42. thy _grow (my numberOfStrings);
  43. for (integer i = 1; i <= my numberOfStrings; i ++) {
  44. autoSimpleString s = SimpleString_create (my strings [i].get());
  45. thy addItem_move (s.move());
  46. }
  47. return thee;
  48. } catch (MelderError) {
  49. Melder_throw (me, U": not converted.");
  50. }
  51. }
  52. /* End of file Categories_and_Strings.cpp */