Debian Codegraph @

melder/MelderArg.h

raw
1 #ifndef _melder_arg_h_
2 #define _melder_arg_h_
3 /* MelderArg.h
4 *
5 * Copyright (C) 1992-2020,2022,2024-2026 Paul Boersma
6 *
7 * This code is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or (at
10 * your option) any later version.
11 *
12 * This code is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this work. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 typedef class structThing *Thing; // forward declaration
22 typedef const class structThing *constThing; // forward declaration
23 conststring32 Thing_messageName (constThing me);
24
25 struct MelderArg {
26 const conststring32 _arg;
27 /*
28 The types of arguments that never involve memory allocation:
29 */
30 MelderArg (conststring32 arg) : _arg (arg) { }
31 MelderArg (const double arg) : _arg (Melder_double (arg)) { }
32 MelderArg (const long long arg) : _arg (Melder_integer (arg)) { }
33 MelderArg (const unsigned long long arg) : _arg (Melder_integer ((int64) arg)) { }
34 MelderArg (const long arg) : _arg (Melder_integer (arg)) { }
35 MelderArg (const unsigned long arg) : _arg (Melder_integer ((int64) arg)) { } // ignore ULL above 2^63
36 MelderArg (const int arg) : _arg (Melder_integer (arg)) { }
37 MelderArg (const unsigned int arg) : _arg (Melder_integer (arg)) { }
38 MelderArg (const short arg) : _arg (Melder_integer (arg)) { }
39 MelderArg (const unsigned short arg) : _arg (Melder_integer (arg)) { }
40 MelderArg (const dcomplex arg) : _arg (Melder_dcomplex (arg)) { }
41 MelderArg (const char32 arg) : _arg (Melder_character (arg)) { }
42 MelderArg (const MelderColour arg) : _arg (Melder_colour (arg)) { }
43 /*
44 The types of arguments that sometimes involve memory allocation:
45 */
46 MelderArg (constVECVU const& arg) : _arg (Melder_VEC (arg)) { }
47 MelderArg (constMATVU const& arg) : _arg (Melder_MAT (arg)) { }
48 MelderArg (constSTRVEC const& arg) : _arg (Melder_STRVEC (arg)) { }
49 MelderArg (VECVU const& arg) : _arg (Melder_VEC (arg)) { }
50 MelderArg (MATVU const& arg) : _arg (Melder_MAT (arg)) { }
51 MelderArg (STRVEC const& arg) : _arg (Melder_STRVEC (arg)) { }
52 MelderArg (constThing arg) : _arg (Thing_messageName (arg)) { }
53 MelderArg (MelderFile arg) : _arg (MelderFile_messageName (arg)) { }
54 MelderArg (MelderFolder arg) : _arg (MelderFolder_messageName (arg)) { }
55 /*
56 There could be more types of arguments, but those are rare;
57 you have to use explicit conversion to one of the types above.
58 For instance, you can write a char* string by using Melder_peek8to32_u()
59 (which sometimes involves memory allocation),
60 and you can write a void* by using Melder_pointer()
61 (which never involves memory allocation).
62 */
63 };
64
65 template <typename... Arg>
66 integer MelderArg__length (const Arg... arg) {
67 return
68 (// fold
69 Melder_length (MelderArg { arg }. _arg)
70 + ... + 0
71 );
72 }
73
74 /* End of file MelderArg.h */
75 #endif