File: args.h

package info (click to toggle)
mrtrix 0.2.12-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,980 kB
  • ctags: 4,172
  • sloc: cpp: 26,485; python: 913; xml: 39; makefile: 22; sh: 10
file content (337 lines) | stat: -rw-r--r-- 7,745 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
    Copyright 2008 Brain Research Institute, Melbourne, Australia

    Written by J-Donald Tournier, 27/06/08.

    This file is part of MRtrix.

    MRtrix is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MRtrix is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with MRtrix.  If not, see <http://www.gnu.org/licenses/>.

*/

#ifndef __args_h__
#define __args_h__

#include "ptr.h"
#include "image/object.h"

namespace MR {
  namespace Image { 
    class Object; 
    class Header;
  }

  namespace Dialog {
    class Window;
    class Argument;
  }

  typedef enum {
    Undefined,
    Integer,
    Float,
    Text,
    ArgFile,
    Choice,
    ImageIn,
    ImageOut,
    IntSeq,
    FloatSeq
  } ArgType;

  const gchar* argument_type_description (ArgType type);


  class ArgData {
    public:
      ArgData ();
      ArgType   type;
      union {
        int         i;
        float       f;
        const gchar* string;
      } data;

      RefPtr<Image::Object>  image;
      friend std::ostream& operator<< (std::ostream& stream, const ArgData& a)
      {
        stream << "{ arg type: " << a.type << " }";
        return (stream);
      }
  };





  class Argument;

  class ArgBase {
    protected:
      RefPtr<ArgData> data;

    public:
      ArgBase ();
      ArgBase (const Argument& arg, const gchar* string);

      int                 get_int () const;
      float               get_float () const;
      const gchar*         get_string () const;
      RefPtr<Image::Object>  get_image () const;
      RefPtr<Image::Object>  get_image (Image::Header& header) const;

      ArgType              type () const;

      friend std::ostream& operator<< (std::ostream& stream, const ArgBase& arg);
      friend class Dialog::Window;
      friend class Dialog::Argument;
      friend class Image::Object;
  };





  class OptBase : public std::vector<ArgBase> {
    public:
      guint index;

      friend std::ostream& operator<< (std::ostream& stream, const OptBase& opt);
      friend class Dialog::Window;
  };



  class Argument {
    friend class ArgBase;
    public:
      Argument ();
      Argument (const gchar* Short_Name, 
          const gchar* Long_Name, 
          const gchar* Description, 
          bool Mandatory = true, 
          bool Allow_Multiple = false);

      const gchar* sname;
      const gchar* lname;
      const gchar* desc;
      bool mandatory, allow_multiple;
      ArgType type;

      union {
        struct { int def, min, max; }     i;
        struct { float def, min, max; }   f;
        const gchar*                       string;
        const gchar**                      choice;
      } extra_info;

      const Argument& type_integer (int lowest, int highest, int default_value);
      const Argument& type_float   (float lowest, float highest, float default_value);
      const Argument& type_string  (const gchar* default_value = NULL);
      const Argument& type_file    ();
      const Argument& type_image_in ();
      const Argument& type_image_out ();
      const Argument& type_choice  (const gchar** choices);
      const Argument& type_sequence_int ();
      const Argument& type_sequence_float ();

      bool    is_valid () const;

      static const Argument End;
      friend std::ostream& operator<< (std::ostream& stream, const Argument& arg);
  };





  class Option : public std::vector<Argument> {
    public:
      Option ();
      Option (const gchar* Short_Name, 
          const gchar* Long_Name,
          const gchar* Description,
          bool Mandatory = false, 
          bool Allow_Multiple = false);

      const gchar* sname;
      const gchar* lname;
      const gchar* desc;
      bool mandatory, allow_multiple;

      Option& append (const Argument& argument);
      bool    is_valid () const;

      friend std::ostream& operator<< (std::ostream& stream, const Option& opt);
      friend std::ostream& operator<< (std::ostream& stream, const OptBase& opt);

      static const Option End;
  };









  inline ArgData::ArgData () : type (Undefined) { data.string = NULL; }

  inline ArgBase::ArgBase () { }

  inline int         ArgBase::get_int () const     { return (data->data.i); }
  inline float       ArgBase::get_float () const   { return (data->data.f); }
  inline const gchar* ArgBase::get_string () const  { return (data->data.string); }
  inline RefPtr<Image::Object> ArgBase::get_image () const   { assert (type() == ImageIn); return (data->image); }
  inline RefPtr<Image::Object> ArgBase::get_image (Image::Header& header) const
  {
    assert (type() == ImageOut);
    data->image->create (get_string(), header);
    return (data->image); 
  }


  inline ArgType ArgBase::type () const { return (!data ? Undefined : data->type ); }







  inline Argument::Argument () : type (Undefined) { sname = lname = desc = NULL; } 


  inline Argument::Argument (
      const gchar* Short_Name,
      const gchar* Long_Name,
      const gchar* Description,
      bool Mandatory,
      bool Allow_Multiple) :
    sname (Short_Name),
    lname (Long_Name),
    desc (Description),
    mandatory (Mandatory),
    allow_multiple (Allow_Multiple)
  {
  }



  inline bool Argument::is_valid () const { return (sname); }




  inline const Argument& Argument::type_integer (int lowest, int highest, int default_value)
  {
    type = Integer;
    extra_info.i.def = default_value;
    extra_info.i.min = lowest;
    extra_info.i.max = highest;
    return (*this);
  }

  inline const Argument& Argument::type_float (float lowest, float highest, float default_value)
  {
    type = Float;
    extra_info.f.def = default_value;
    extra_info.f.min = lowest;
    extra_info.f.max = highest;
    return (*this);
  }

  inline const Argument& Argument::type_string (const gchar* default_value)
  {
    type = Text;
    extra_info.string = default_value;
    return (*this);
  }

  inline const Argument& Argument::type_choice (const gchar** choices)
  {
    type = Choice;
    extra_info.choice = choices;
    return (*this);
  }

  inline const Argument& Argument::type_file ()
  {
    type = ArgFile;
    extra_info.string = NULL;
    return (*this);
  }

  inline const Argument& Argument::type_image_in ()
  {
    type = ImageIn;
    extra_info.string = NULL;
    return (*this);
  }

  inline const Argument& Argument::type_image_out ()
  {
    type = ImageOut;
    extra_info.string = NULL;
    return (*this);
  }

  inline const Argument& Argument::type_sequence_int ()
  {
    type = IntSeq;
    extra_info.string = NULL;
    return (*this);
  }

  inline const Argument& Argument::type_sequence_float ()
  {
    type = FloatSeq;
    extra_info.string = NULL;
    return (*this);
  }






  inline Option::Option () { sname = lname = desc = NULL; } 

  inline Option::Option (
      const gchar* Short_Name, 
      const gchar* Long_Name,
      const gchar* Description,
      bool Mandatory,
      bool Allow_Multiple) :
    sname (Short_Name),
    lname (Long_Name),
    desc (Description),
    mandatory (Mandatory),
    allow_multiple (Allow_Multiple)
  {
  }

  inline Option& Option::append (const Argument& argument)
  {
    std::vector<Argument>::push_back (argument);
    return (*this);
  }

  inline bool Option::is_valid () const { return (sname); }
  
}

#endif