MelderArg.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef _melder_arg_h_
  2. #define _melder_arg_h_
  3. /* MelderArg.h
  4. *
  5. * Copyright (C) 1992-2018 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 2 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. typedef class structThing *Thing; // forward declaration
  21. conststring32 Thing_messageName (Thing me);
  22. struct MelderArg {
  23. const conststring32 _arg;
  24. /*
  25. The types of arguments that never involve memory allocation:
  26. */
  27. MelderArg (conststring32 arg) : _arg (arg) { }
  28. MelderArg (const double arg) : _arg (Melder_double (arg)) { }
  29. MelderArg (const long long arg) : _arg (Melder_integer (arg)) { }
  30. MelderArg (const unsigned long long arg) : _arg (Melder_integer ((int64) arg)) { }
  31. MelderArg (const long arg) : _arg (Melder_integer (arg)) { }
  32. MelderArg (const unsigned long arg) : _arg (Melder_integer ((int64) arg)) { } // ignore ULL above 2^63
  33. MelderArg (const int arg) : _arg (Melder_integer (arg)) { }
  34. MelderArg (const unsigned int arg) : _arg (Melder_integer (arg)) { }
  35. MelderArg (const short arg) : _arg (Melder_integer (arg)) { }
  36. MelderArg (const unsigned short arg) : _arg (Melder_integer (arg)) { }
  37. MelderArg (const dcomplex arg) : _arg (Melder_dcomplex (arg)) { }
  38. MelderArg (const char32 arg) : _arg (Melder_character (arg)) { }
  39. /*
  40. The types of arguments that sometimes involve memory allocation:
  41. */
  42. MelderArg (constVEC arg) : _arg (Melder_VEC (arg)) { }
  43. MelderArg (constMAT arg) : _arg (Melder_MAT (arg)) { }
  44. MelderArg (Thing arg) : _arg (Thing_messageName (arg)) { }
  45. MelderArg (MelderFile arg) : _arg (MelderFile_messageName (arg)) { }
  46. /*
  47. There could be more types of arguments, but those are rare;
  48. you have to use explicit conversion to one of the types above.
  49. For instance, you can write a char* string by using Melder_peek8to32()
  50. (which sometimes involves memory allocation),
  51. and you can write a void* by using Melder_pointer()
  52. (which never involves memory allocation).
  53. */
  54. };
  55. inline static integer MelderArg__length (const MelderArg& arg) {
  56. return arg._arg ? str32len (arg._arg) : 0;
  57. }
  58. template <typename... Args>
  59. integer MelderArg__length (const MelderArg& first, Args... rest) {
  60. integer length = MelderArg__length (first);
  61. length += MelderArg__length (rest...);
  62. return length;
  63. }
  64. /* End of file MelderArg.h */
  65. #endif