Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
io.h
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // Copyright (c) 1997 The CGAL Consortium
4 
5 // This software and related documentation is part of the Computational
6 // Geometry Algorithms Library (CGAL).
7 // This software and documentation is provided "as-is" and without warranty
8 // of any kind. In no event shall the CGAL Consortium be liable for any
9 // damage of any kind.
10 //
11 // Every use of CGAL requires a license.
12 //
13 // Academic research and teaching license
14 // - For academic research and teaching purposes, permission to use and copy
15 // the software and its documentation is hereby granted free of charge,
16 // provided that it is not a component of a commercial product, and this
17 // notice appears in all copies of the software and related documentation.
18 //
19 // Commercial licenses
20 // - A commercial license is available through Algorithmic Solutions, who also
21 // markets LEDA (http://www.algorithmic-solutions.de).
22 // - Commercial users may apply for an evaluation license by writing to
23 // Algorithmic Solutions (contact@algorithmic-solutions.com).
24 //
25 // The CGAL Consortium consists of Utrecht University (The Netherlands),
26 // ETH Zurich (Switzerland), Free University of Berlin (Germany),
27 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
28 // (Germany), Max-Planck-Institute Saarbrucken (Germany), RISC Linz (Austria),
29 // and Tel-Aviv University (Israel).
30 //
31 // ----------------------------------------------------------------------
32 //
33 // release : CGAL-2.2
34 // release_date : 2000, September 30
35 //
36 // file : include/CGAL/IO/io.h
37 // package : iostream (2.8)
38 // source : $RCSfile: io.h,v $
39 // revision : $Revision: 1.1.1.1 $
40 // revision_date : $Date: 2001/07/05 22:17:48 $
41 // author(s) : Andreas Fabri
42 //
43 // coordinator : Mariette Yvinec
44 //
45 // email : contact@cgal.org
46 // www : http://www.cgal.org
47 //
48 // ======================================================================
49 
50 
51 #ifndef CGAL_IO_H
52 #define CGAL_IO_H
53 
54 #include <iostream>
55 #include <CGAL/IO/io_tags.h>
56 #include <CGAL/IO/Color.h>
57 #include <CGAL/Object.h>
58 
60 
61 class IO {
62 public:
63  static int mode;
64  enum Mode {ASCII = 0, PRETTY, BINARY};
65 };
66 
68 get_mode(std::ios& i);
69 
71 set_ascii_mode(std::ios& i);
72 
74 set_binary_mode(std::ios& i);
75 
77 set_pretty_mode(std::ios& i);
78 
80 set_mode(std::ios& i, IO::Mode m);
81 bool
82 is_pretty(std::ios& i);
83 
84 bool
85 is_ascii(std::ios& i);
86 
87 bool
88 is_binary(std::ios& i);
89 
90 inline io_Read_write io_tag(char){ return io_Read_write(); }
91 
92 
93 template < class T >
94 inline
95 void
96 write(std::ostream& os, const T& t, const io_Read_write&)
97 {
98  os.write((char*)&t, sizeof(t));
99 }
100 
101 
102 template < class T >
103 inline
104 void
105 write(std::ostream& os, const T& t, const io_Operator&)
106 {
107  os << t;
108 }
109 
110 
111 template < class T >
112 inline
113 void
114 write(std::ostream& os, const T& t, const io_Extract_insert&)
115 {
116  insert(os, t);
117 }
118 
119 
120 template < class T >
121 inline
122 void
123 write(std::ostream& os, const T& t)
124 {
125  write(os, t, io_tag(t));
126 }
127 
128 
129 template < class T >
130 inline
131 void
132 read(std::istream& is, T& t, const io_Read_write&)
133 {
134  is.read((char*)&t, sizeof(t));
135 }
136 
137 
138 template < class T >
139 inline
140 void
141 read(std::istream& is, T& t, const io_Operator&)
142 {
143  is >> t;
144 }
145 
146 
147 template < class T >
148 inline
149 void
150 read(std::istream& is, T& t, const io_Extract_insert&)
151 {
152  extract(is, t);
153 }
154 
155 
156 template < class T >
157 inline
158 void
159 read(std::istream& is, T& t)
160 {
161  read(is, t, io_tag(t));
162 }
163 
164 
165 inline
166 std::ostream& operator<<( std::ostream& out, const Color& col)
167 {
168  switch(out.iword(IO::mode)) {
169  case IO::ASCII :
170  return out << static_cast<int>(col.red()) << ' '
171  << static_cast<int>(col.green()) << ' '
172  << static_cast<int>(col.blue());
173  case IO::BINARY :
174  write(out, static_cast<int>(col.red()));
175  write(out, static_cast<int>(col.green()));
176  write(out, static_cast<int>(col.blue()));
177  return out;
178  default:
179  return out << "Color(" << static_cast<int>(col.red()) << ", "
180  << static_cast<int>(col.green()) << ", "
181  << static_cast<int>(col.blue()) << ')';
182  }
183 }
184 
185 inline
186 std::istream &operator>>(std::istream &is, Color& col)
187 {
188  int r, g, b;
189  switch(is.iword(IO::mode)) {
190  case IO::ASCII :
191  is >> r >> g >> b;
192  break;
193  case IO::BINARY :
194  read(is, r);
195  read(is, g);
196  read(is, b);
197  break;
198  default:
199  std::cerr << "" << std::endl;
200  std::cerr << "Stream must be in ascii or binary mode" << std::endl;
201  break;
202  }
203  col = Color(r,g,b);
204  return is;
205 }
206 
208 
209 #endif // CGAL_IO_H
IO::Mode get_mode(std::ios &i)
Definition: io.C:64
io_Operator io_tag(double)
Definition: double.h:200
Definition: io.h:61
unsigned char blue() const
Definition: Color.h:74
Definition: io.h:64
bool is_pretty(std::ios &i)
Definition: io.C:105
Definition: io.h:64
IO::Mode set_binary_mode(std::ios &i)
Definition: io.C:79
Mode
Definition: io.h:64
bool is_binary(std::ios &i)
Definition: io.C:118
void write(std::ostream &os, const T &t, const io_Read_write &)
Definition: io.h:96
blockLoc i
Definition: read.cpp:79
bool is_ascii(std::ios &i)
Definition: io.C:111
static int mode
Definition: io.h:63
Definition: io.h:64
Color
Definition: rfc_basic.h:48
unsigned char green() const
Definition: Color.h:73
void read(std::istream &is, T &t, const io_Read_write &)
Definition: io.h:132
Definition: Color.h:58
IO::Mode set_mode(std::ios &i, IO::Mode m)
Definition: io.C:97
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
std::istream & operator>>(std::istream &is, CGAL::Aff_transformation_2< R > &t)
std::ostream & operator<<(std::ostream &os, const COM_exception &ex)
Print out a given exception.
IO::Mode set_ascii_mode(std::ios &i)
Definition: io.C:70
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
unsigned char red() const
Definition: Color.h:72
IO::Mode set_pretty_mode(std::ios &i)
Definition: io.C:88