vtkbone
vtkboneMacros.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Copyright 2010-2016, Numerics88 Solutions Ltd.
4 http://www.numerics88.com/
5
6 Copyright (c) Eric Nodwell and Steven K. Boyd
7 See Copyright.txt for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12=========================================================================*/
13
14#ifndef __vtkboneMacros_h
15#define __vtkboneMacros_h
16
17// Define a function to string value for an enum.
18// This requires:
19// 1. An enum defined in a class, and named (enumname)_t
20// 2. The last value of the enum must be NUMBER_OF_(enumname)
21// 3. Declare the function like this in the header file:
22// static const char* Get(enumname)AsString (enumname_t arg);
23// 4. Make a list of string values for your enum in the .cxx file, like this:
24// const char* const (enumname)_s[] = {"BLUE", "RED", "GREEN"};
25// 5. Put this macro right after the list of string values
26#define vtkboneGetAsStringMacro(classname,enumname) \
27const char* classname::Get##enumname##AsString (int arg) \
28{ \
29 if (arg >=0 && arg < classname::NUMBER_OF_##enumname) \
30 { \
31 return enumname##_s[arg]; \
32 } \
33 else \
34 { \
35 return NULL; \
36 } \
37}
38
39//
40// Set character string. Creates member Set"name"()
41// (e.g., SetFilename(char *));
42// Modified from vtkSetStringMacro
43//
44#define vtkboneSetStringMacro(name) \
45 virtual void Set##name(const char* _arg) vtkboneSetStringBodyMacro(name, _arg)
46
47// This macro defines a body of set string macro. It can be used either in
48// the header file using vtkSetStringMacro or in the implementation.
49// Modified from vtkboneSetStringBodyMacro
50#define vtkboneSetStringBodyMacro(name, _arg) \
51 { \
52 if (this->name == nullptr && _arg == nullptr) \
53 { \
54 return; \
55 } \
56 if (this->name && _arg && (!strcmp(this->name, _arg))) \
57 { \
58 return; \
59 } \
60 delete[] this->name; \
61 if (_arg) \
62 { \
63 size_t n = strlen(_arg) + 1; \
64 char* cp1 = new char[n]; \
65 const char* cp2 = (_arg); \
66 this->name = cp1; \
67 do \
68 { \
69 *cp1++ = *cp2++; \
70 } while (--n); \
71 } \
72 else \
73 { \
74 this->name = nullptr; \
75 } \
76 this->Modified(); \
77 }
78
79//
80// Get character string. Creates member Get"name"()
81// (e.g., char *GetFilename());
82// Modified from vtkboneGetStringMacro
83//
84#define vtkboneGetStringMacro(name) \
85 virtual char* Get##name() \
86 { \
87 return this->name; \
88 }
89
90#endif