Debian Codegraph @

dwtools/Categories_and_Strings.cpp

raw
1 /* Categories_and_Strings.cpp
2 *
3 * Copyright (C) 1993-2018 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 /*
20 djmw 20020315 GPL header
21 djmw 20110304 Thing_new
22 */
23
24 #include "Categories_and_Strings.h"
25
26 autoStrings Categories_to_Strings (Categories me) {
27 try {
28 Melder_require (my size > 0,
29 U"There should be at least one category present.");
30
31 autoStrings thee = Thing_new (Strings);
32 thy strings = autoSTRVEC (my size);
33 thy numberOfStrings = my size;
34
35 for (integer i = 1; i <= my size; i ++) {
36 const SimpleString s = my at [i];
37 thy strings [i] = Melder_dup (s -> string.get());
38 }
39 return thee;
40 } catch (MelderError) {
41 Melder_throw (me, U": not converted to Strings.");
42 }
43 }
44
45 autoCategories Strings_to_Categories (Strings me) {
46 try {
47 Melder_require (my numberOfStrings > 0, U"Empty strings.");
48
49 autoCategories thee = Thing_new (Categories);
50 thy _grow (my numberOfStrings);
51
52 for (integer i = 1; i <= my numberOfStrings; i ++) {
53 autoSimpleString s = SimpleString_create (my strings [i].get());
54 thy addItem_move (s.move());
55 }
56 return thee;
57 } catch (MelderError) {
58 Melder_throw (me, U": not converted.");
59 }
60 }
61
62 /* End of file Categories_and_Strings.cpp */