matlaboption.h
Go to the documentation of this file.
1 // Copyright (C) 2007 Peter Carbonetto. All Rights Reserved.
2 // This code is published under the Eclipse Public License.
3 //
4 // Author: Peter Carbonetto
5 // Dept. of Computer Science
6 // University of British Columbia
7 // May 19, 2007
8 
9 #ifndef INCLUDE_MATLABOPTION
10 #define INCLUDE_MATLABOPTION
11 
12 #include "mex.h"
13 #include <string>
14 
15 // Class MatlabOption.
16 // -----------------------------------------------------------------
17 class MatlabOption {
18 public:
19 
20  // This constructor creates an object starting from a Matlab
21  // array. The Matlab array must either be a string or a scalar in
22  // double precision.
23  MatlabOption (const mxArray* ptr);
24 
25  // Return "true" if the option value is a string.
26  bool isString() const { return s; };
27 
28  // Get the option value.
29  operator const char* () const { return s->c_str(); };
30  operator const std::string& () const { return *s; };
31  operator double () const { return x; };
32  operator int () const { return (int) x; };
33 
34  // The destructor.
35  ~MatlabOption();
36 
37 protected:
38  std::string* s; // The string value.
39  double x; // The double value.
40 };
41 
42 #endif