Point Cloud Library (PCL)  1.9.1
io_operators.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2007-2012, Ares Lagae
6  * Copyright (c) 2012, Willow Garage, Inc.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id$
37  *
38  */
39 
40 #ifndef PCL_IO_PLY_IO_OPERATORS_H
41 #define PCL_IO_PLY_IO_OPERATORS_H
42 
43 #include <istream>
44 #include <limits>
45 #include <ostream>
46 
47 namespace pcl
48 {
49  namespace io
50  {
51  namespace ply
52  {
53  /** \file io_operators.h
54  * defines output operators for int8 and uint8
55  * \author Ares Lagae as part of libply, Nizar Sallem
56  * \ingroup io
57  */
58  namespace io_operators
59  {
60 
61  inline std::istream& operator>> (std::istream& istream, int8 &value)
62  {
63  int16 tmp;
64  if (istream >> tmp)
65  {
66  if (tmp <= std::numeric_limits<int8>::max ())
67  value = static_cast<int8> (tmp);
68  else
69  istream.setstate (std::ios_base::failbit);
70  }
71  return (istream);
72  }
73 
74  inline std::istream& operator>> (std::istream& istream, uint8 &value)
75  {
76  uint16 tmp;
77  if (istream >> tmp)
78  {
79  if (tmp <= std::numeric_limits<uint8>::max ())
80  value = static_cast<uint8> (tmp);
81  else
82  istream.setstate (std::ios_base::failbit);
83  }
84  return (istream);
85  }
86 
87  inline std::ostream& operator<<(std::ostream& ostream, int8 value)
88  {
89  return (ostream << static_cast<int16> (value));
90  }
91 
92  inline std::ostream& operator<<(std::ostream& ostream, uint8 value)
93  {
94  return (ostream << static_cast<uint16> (value));
95  }
96 
97  } // namespace io_operators
98  } // namespace ply
99  } // namespace io
100 } // namespace pcl
101 
102 #endif // PLY_IO_OPERATORS_H
boost::int16_t int16
Definition: ply.h:60
std::istream & operator>>(std::istream &istream, int8 &value)
Definition: io_operators.h:61
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
std::ostream & operator<<(std::ostream &ostream, int8 value)
Definition: io_operators.h:87
boost::int8_t int8
Definition: ply.h:59
boost::uint16_t uint16
Definition: ply.h:63
boost::uint8_t uint8
Definition: ply.h:62