ViSP  2.9.0
testMatrixException.cpp
1 /****************************************************************************
2  *
3  * $Id: testMatrixException.cpp 4658 2014-02-09 09:50:14Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Test matrix exceptions.
36  *
37  * Authors:
38  * Eric Marchand
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
48 #include <visp/vpMath.h>
49 #include <visp/vpMatrix.h>
50 #include <visp/vpMatrixException.h>
51 #include <visp/vpDebug.h>
52 
53 #include <visp/vpParseArgv.h>
54 
55 #include <stdlib.h>
56 #include <stdio.h>
57 
58 // List of allowed command line options
59 #define GETOPTARGS "h"
60 
61 void usage(const char *name, const char *badparam);
62 bool getOptions(int argc, const char **argv);
63 
69 void usage(const char *name, const char *badparam)
70 {
71  fprintf(stdout, "\n\
72 Test some vpMatrix functionalities.\n\
73 \n\
74 SYNOPSIS\n\
75  %s [-h]\n", name);
76 
77  fprintf(stdout, "\n\
78 OPTIONS: Default\n\
79  -h\n\
80  Print the help.\n");
81 
82  if (badparam)
83  fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
84 }
92 bool getOptions(int argc, const char **argv)
93 {
94  const char *optarg_;
95  int c;
96  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
97 
98  switch (c) {
99  case 'h': usage(argv[0], NULL); return false; break;
100 
101  default:
102  usage(argv[0], optarg_);
103  return false; break;
104  }
105  }
106 
107  if ((c == 1) || (c == -1)) {
108  // standalone param or error
109  usage(argv[0], NULL);
110  std::cerr << "ERROR: " << std::endl;
111  std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
112  return false;
113  }
114 
115  return true;
116 }
117 
118 
119 int
120 main(int argc, const char ** argv)
121 {
122  try {
123  // Read the command line options
124  if (getOptions(argc, argv) == false) {
125  exit (-1);
126  }
127 
128  vpMatrix M ;
129  vpMatrix M1(2,3) ;
130  vpMatrix M2(3,3) ;
131  vpMatrix M3(2,2) ;
132 
133  vpTRACE("test matrix size in multiply") ;
134 
135  try
136  {
137  M = M1*M3 ;
138  }
139  catch (vpMatrixException me)
140  {
141  std::cout << me << std::endl ;
142  }
143 
144 
145  vpTRACE("test matrix size in addition") ;
146 
147  try
148  {
149  M = M1+M3 ;
150  }
151  catch (vpMatrixException me)
152  {
153  std::cout << me << std::endl ;
154  }
155  }
156  catch(vpException e) {
157  std::cout << "Catch an exception: " << e << std::endl;
158  return 1;
159  }
160 }
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
#define vpTRACE
Definition: vpDebug.h:418
error that can be emited by ViSP classes.
Definition: vpException.h:76
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:79
error that can be emited by the vpMatrix class and its derivates