| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation,  | 
					
						
							|  |  |  |  * Atlanta, Georgia 30332-0415 | 
					
						
							|  |  |  |  * All Rights Reserved | 
					
						
							|  |  |  |  * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * See LICENSE for the license information | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2012-06-27 02:52:27 +08:00
										 |  |  |  * @file utilities.h | 
					
						
							| 
									
										
										
										
											2011-10-14 11:23:14 +08:00
										 |  |  |  * @author Frank Dellaert | 
					
						
							| 
									
										
										
										
											2012-06-27 02:52:27 +08:00
										 |  |  |  * @author Andrew Melim | 
					
						
							| 
									
										
										
										
											2012-07-13 06:28:28 +08:00
										 |  |  |  * @author Richard Roberts | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  |  **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 06:22:59 +08:00
										 |  |  | #include "FileWriter.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/format.hpp>
 | 
					
						
							|  |  |  | #include <boost/foreach.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2011-12-10 04:29:47 +08:00
										 |  |  | #include <vector>
 | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | #include <exception>
 | 
					
						
							| 
									
										
										
										
											2011-12-10 04:29:47 +08:00
										 |  |  | #include <fstream>
 | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | #include <sstream>
 | 
					
						
							| 
									
										
										
										
											2014-11-13 06:22:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-10 22:21:56 +08:00
										 |  |  | //#include <cstdint> // on Linux GCC: fails with error regarding needing C++0x std flags
 | 
					
						
							|  |  |  | //#include <cinttypes>  // same failure as above
 | 
					
						
							|  |  |  | #include <stdint.h> // works on Linux GCC
 | 
					
						
							| 
									
										
										
										
											2012-01-16 05:42:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 00:43:15 +08:00
										 |  |  | namespace wrap { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | class CantOpenFile : public std::exception { | 
					
						
							|  |  |  |  private: | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   const std::string what_; | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  |  public: | 
					
						
							| 
									
										
										
										
											2012-07-10 04:19:37 +08:00
										 |  |  |  CantOpenFile(const std::string& filename) : what_("Can't open file " + filename) {} | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  |   ~CantOpenFile() throw() {} | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   virtual const char* what() const throw() { return what_.c_str(); } | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-18 23:47:06 +08:00
										 |  |  | class OutputError : public std::exception { | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   const std::string what_; | 
					
						
							| 
									
										
										
										
											2012-07-18 23:47:06 +08:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   OutputError(const std::string& what) : what_(what) {} | 
					
						
							|  |  |  |   ~OutputError() throw() {} | 
					
						
							|  |  |  |   virtual const char* what() const throw() { return what_.c_str(); } | 
					
						
							| 
									
										
										
										
											2012-07-18 23:47:06 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | class ParseFailed : public std::exception { | 
					
						
							|  |  |  |  private: | 
					
						
							| 
									
										
										
										
											2012-07-10 04:19:37 +08:00
										 |  |  |   const std::string what_; | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  |  public: | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |    ParseFailed(int length) : what_((boost::format("Parse failed at character [%d]")%(length-1)).str()) {} | 
					
						
							|  |  |  |    ~ParseFailed() throw() {} | 
					
						
							|  |  |  |    virtual const char* what() const throw() { return what_.c_str(); } | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-08 01:55:38 +08:00
										 |  |  | class DependencyMissing : public std::exception { | 
					
						
							| 
									
										
										
										
											2012-01-16 05:42:41 +08:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   const std::string what_; | 
					
						
							| 
									
										
										
										
											2012-01-16 05:42:41 +08:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   DependencyMissing(const std::string& dep, const std::string& loc) : | 
					
						
							| 
									
										
										
										
											2014-11-30 23:08:08 +08:00
										 |  |  |     what_("Missing dependency '" + dep + "' in " + loc) {} | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   ~DependencyMissing() throw() {} | 
					
						
							|  |  |  |   virtual const char* what() const throw() { return what_.c_str(); } | 
					
						
							| 
									
										
										
										
											2012-07-10 04:19:37 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class DuplicateDefinition : public std::exception { | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   const std::string what_; | 
					
						
							| 
									
										
										
										
											2012-07-10 04:19:37 +08:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   DuplicateDefinition(const std::string& name) : | 
					
						
							|  |  |  |     what_("Duplicate definition of " + name) {} | 
					
						
							|  |  |  |   ~DuplicateDefinition() throw() {} | 
					
						
							|  |  |  |   virtual const char* what() const throw() { return what_.c_str(); } | 
					
						
							| 
									
										
										
										
											2011-12-08 01:55:38 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2012-07-11 06:38:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class AttributeError : public std::exception { | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   const std::string what_; | 
					
						
							| 
									
										
										
										
											2012-07-11 06:38:21 +08:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   AttributeError(const std::string& name, const std::string& problem) : | 
					
						
							|  |  |  |     what_("Class " + name + ": " + problem) {} | 
					
						
							|  |  |  |   ~AttributeError() throw() {} | 
					
						
							|  |  |  |   virtual const char* what() const throw() { return what_.c_str(); } | 
					
						
							| 
									
										
										
										
											2012-07-11 06:38:21 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2014-01-10 05:38:47 +08:00
										 |  |  | // "Unique" key to signal calling the matlab object constructor with a raw pointer
 | 
					
						
							|  |  |  | // to a shared pointer of the same C++ object type as the MATLAB type.
 | 
					
						
							| 
									
										
										
										
											2012-07-11 23:44:04 +08:00
										 |  |  | // Also present in matlab.h
 | 
					
						
							| 
									
										
										
										
											2012-07-09 08:02:43 +08:00
										 |  |  | static const uint64_t ptr_constructor_key = | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   (uint64_t('G') << 56) | | 
					
						
							|  |  |  |   (uint64_t('T') << 48) | | 
					
						
							|  |  |  |   (uint64_t('S') << 40) | | 
					
						
							|  |  |  |   (uint64_t('A') << 32) | | 
					
						
							|  |  |  |   (uint64_t('M') << 24) | | 
					
						
							|  |  |  |   (uint64_t('p') << 16) | | 
					
						
							|  |  |  |   (uint64_t('t') << 8) | | 
					
						
							|  |  |  |   (uint64_t('r')); | 
					
						
							| 
									
										
										
										
											2011-12-08 01:55:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * read contents of a file into a std::string | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | std::string file_contents(const std::string& filename, bool skipheader=false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Check whether two files are equal | 
					
						
							|  |  |  |  * By default, skips the first line of actual so header is not generated | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-02-07 03:45:40 +08:00
										 |  |  | bool files_equal(const std::string& expected, const std::string& actual, bool skipheader=false); | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 02:57:32 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Compare strings for unit tests | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | bool assert_equal(const std::string& expected, const std::string& actual); | 
					
						
							| 
									
										
										
										
											2011-12-16 03:39:11 +08:00
										 |  |  | bool assert_equal(const std::vector<std::string>& expected, const std::vector<std::string>& actual); | 
					
						
							| 
									
										
										
										
											2011-12-02 10:32:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // auxiliary function to wrap an argument into a shared_ptr template
 | 
					
						
							| 
									
										
										
										
											2012-06-27 02:52:27 +08:00
										 |  |  | std::string maybe_shared_ptr(bool add, const std::string& qtype, const std::string& type); | 
					
						
							| 
									
										
										
										
											2011-12-03 00:43:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-08 20:27:39 +08:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2014-11-12 09:49:23 +08:00
										 |  |  |  * Return a qualified name | 
					
						
							| 
									
										
										
										
											2012-07-08 20:27:39 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-11-12 09:49:23 +08:00
										 |  |  | std::string qualifiedName(const std::string& separator, const std::vector<std::string>& names); | 
					
						
							| 
									
										
										
										
											2012-07-08 20:27:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-24 02:24:35 +08:00
										 |  |  | /** creates the necessary folders for namespaces, as specified by a namespace stack */ | 
					
						
							| 
									
										
										
										
											2014-11-12 09:49:23 +08:00
										 |  |  | void createNamespaceStructure(const std::vector<std::string>& namespaces, | 
					
						
							|  |  |  |     const std::string& toolboxPath); | 
					
						
							| 
									
										
										
										
											2012-07-24 02:24:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 00:43:15 +08:00
										 |  |  | } // \namespace wrap
 |