Kindr
Kinematics and Dynamics for Robotics
source_file_pos.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, Christian Gehring, Hannes Sommer, Paul Furgale, Remo Diethelm
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary fokindrs, with or without
6  * modification, are pekindritted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary fokindr must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the Autonomous Systems Lab, ETH Zurich nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written pekindrission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL Christian Gehring, Hannes Sommer, Paul Furgale,
20  * Remo Diethelm BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27 */
28 #ifndef KINDR_COMMON_SOURCE_FILE_POS_HPP
29 #define KINDR_COMMON_SOURCE_FILE_POS_HPP
30 
31 #include <string>
32 #include <iostream>
33 #include <sstream>
34 // A class and macro that gives you the current file position.
35 
36 namespace kindr {
37 namespace internal {
38 
39 class source_file_pos
40 {
41  public:
42  std::string function;
43  std::string file;
44  int line;
45 
46  source_file_pos(std::string function, std::string file, int line) :
47  function(function), file(file), line(line) {}
48 
49  operator std::string()
50  {
51  return toString();
52  }
53 
54  std::string toString() const
55  {
56  std::stringstream s;
57  s << file << ":" << line << ": " << function << "()";
58  return s.str();
59  }
60 
61 };
62 
63 } // namespace internal
64 } // namespace kindr
65 
66 inline std::ostream & operator<<(std::ostream & out, const kindr::internal::source_file_pos & sfp)
67 {
68  out << sfp.file << ":" << std::to_string(sfp.line) << ": " << sfp.function << "()";
69  return out;
70 }
71 
72 
73 #define KINDR_SOURCE_FILE_POS kindr::internal::source_file_pos(__FUNCTION__,__FILE__,__LINE__)
74 
75 #endif
76 
std::ostream & operator<<(std::ostream &out, const kindr::internal::source_file_pos &sfp)