cmtkMacros.h

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2010 SRI International
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2398 $
00026 //
00027 //  $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkMacros_h_included_
00034 #define __cmtkMacros_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <stdlib.h>
00039 #include <string.h>
00040 #include <vector>
00041 
00042 #include <Base/cmtkTypes.h>
00043 
00051 inline void abstract() {
00052 #ifdef DEBUG
00053   abort();
00054 #endif
00055 }
00056 
00060 #define cmtkGetSetMacro(type,name) \
00061   public: type m_##name; \
00062              void Set##name( const type& v ) { this->m_##name = v; } \
00063              const type& Get##name() const { return this->m_##name; } \
00064              type& Get##name() { return this->m_##name; } \
00065              void Get##name( type& to ) { to = this->m_##name; }
00066 
00070 #define cmtkGetSetMacroDefault(type,name,default) \
00071   public: type m_##name; \
00072              void Set##name( const type v = default ) { this->m_##name = v; }    \
00073              const type& Get##name() const { return this->m_##name; } \
00074              type& Get##name() { return this->m_##name; } \
00075              void Get##name( type& to ) { to = this->m_##name; }
00076 
00080 #define cmtkGetSetMacroString(name) \
00081   protected: char *m_##name;                               \
00082   public:    void Set##name( const char* v ) {             \
00083                   if ( (this->m_##name != NULL) ) { if ( v != NULL ) \
00084                     if ( !strcmp( this->m_##name, v ) ) return;    \
00085                   free(this->m_##name); this->m_##name = NULL;                     \
00086                   } else { if ( v == NULL ) return; } \
00087                   if ( v != NULL ) { this->m_##name = strdup(v); } } \
00088              char* Get##name() { return this->m_##name; } \
00089              const char* Get##name() const { return this->m_##name; } \
00090              void Get##name( char*& to ) { to = this->m_##name; }
00091 
00095 #define cmtkGetSetMacroPtr(t,name) \
00096   public: t *m_##name; \
00097              void Set##name( t *const v ) { this->m_##name = v; } \
00098              t* Get##name() { return this->m_##name; } \
00099              const t* Get##name() const { return this->m_##name; } \
00100              void Get##name( t*& to ) { to = this->m_##name; }
00101 
00105 #define cmtkGetSetMacro2Array(type,name) \
00106   public: type m_##name[2];                                 \
00107              void Set##name( const type v0, const type v1 ) \
00108                   { this->m_##name[0] = v0; this->m_##name[1] = v1; } \
00109              void SetByIndex##name( const int axis, const type v )  \
00110                   { this->m_##name[axis] = v; } \
00111              void Set##name( const type* v ) \
00112                   { this->m_##name[0] = v[0]; this->m_##name[1] = v[1]; } \
00113              void Get##name( type &v0, type &v1 ) const \
00114                   { v0 = this->m_##name[0]; v1 = this->m_##name[1]; } \
00115              void Get##name( type *const v ) const \
00116                   { v[0] = this->m_##name[0]; v[1] = this->m_##name[1]; } \
00117              const type* Get##name() const { return this->m_##name; } \
00118              type* Get##name() { return this->m_##name; } \
00119              type Get##name( const int i ) const { return this->m_##name[i]; }
00120 
00124 #define cmtkGetSetMacro3Array(type,name) \
00125   public: type m_##name[3]; \
00126              void Set##name( const type v0, const type v1, const type v2 ) \
00127                   { this->m_##name[0] = v0; this->m_##name[1] = v1; this->m_##name[2] = v2; } \
00128              void SetByIndex##name( const int axis, const type v ) \
00129                   { this->m_##name[axis] = v; } \
00130              void Set##name( const type* v ) \
00131                   { this->m_##name[0] = v[0]; this->m_##name[1] = v[1]; this->m_##name[2] = v[2]; } \
00132              void Get##name( type &v0, type &v1, type &v2 ) const \
00133                   { v0 = this->m_##name[0]; v1 = this->m_##name[1]; v2 = this->m_##name[2]; } \
00134              void Get##name( type *const v ) const \
00135                   { v[0] = this->m_##name[0]; v[1] = this->m_##name[1]; v[2] = this->m_##name[2]; } \
00136              const type* Get##name() const { return this->m_##name; } \
00137              type* Get##name() { return this->m_##name; } \
00138              type Get##name( const int i ) const { return this->m_##name[i]; }
00139 
00143 #define cmtkGetMacro3Array(type,name) \
00144   public: type m_##name[3]; \
00145              void Get##name( type &v0, type &v1, type &v2 ) const \
00146                   { v0 = this->m_##name[0]; v1 = this->m_##name[1]; v2 = this->m_##name[2]; } \
00147              void Get##name( type *const v ) const \
00148                   { v[0] = this->m_##name[0]; v[1] = this->m_##name[1]; v[2] = this->m_##name[2]; } \
00149              const type* Get##name() const { return this->m_##name; } \
00150              type* Get##name() { return this->m_##name; } \
00151              type Get##name( const int i ) const { return this->m_##name[i]; }
00152 
00153 
00154 #endif // #ifndef __cmtkMacros_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines