CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
binary_ofstream.cc
Go to the documentation of this file.
2 
3 #include <cstdio>
4 #include <iostream>
5 
7 
8 binary_ofstream::binary_ofstream( const char* name) : file_(0)
9 {
10  init (name);
11 }
12 
13 binary_ofstream::binary_ofstream( const std::string& name) : file_(0)
14 {
15  init (name.c_str());
16 }
17 
18 void binary_ofstream::init( const char* name)
19 {
20  file_ = fopen( name, "wb");
21  if (file_ == 0) {
22  std::cout << "file " << name << " cannot be opened for writing"
23  << std::endl;
24  throw binary_ofstream_error();
25  }
26 }
27 
29 {
30  close();
31 }
33 {
34  if (file_ != 0) fclose( file_);
35  file_ = 0;
36 }
37 
39  fputc( n, file_); return *this;
40 }
42  fputc( n, file_); return *this;
43 }
44 
46  fwrite( &n, sizeof(n), 1, file_); return *this;}
48  fwrite( &n, sizeof(n), 1, file_); return *this;}
50  fwrite( &n, sizeof(n), 1, file_); return *this;}
52  fwrite( &n, sizeof(n), 1, file_); return *this;}
54  fwrite( &n, sizeof(n), 1, file_); return *this;}
56  fwrite( &n, sizeof(n), 1, file_); return *this;}
58  fwrite( &n, sizeof(n), 1, file_); return *this;}
60  fwrite( &n, sizeof(n), 1, file_); return *this;}
61 
63  return operator<<( static_cast<char>(n));
64 }
65 
67  (*this) << s.size();
68  fwrite( s.data(), 1, s.size(), file_);
69  return *this;
70 }
void init(const char *name)
binary_ofstream(const char *name)
binary_ofstream & operator<<(char n)
tuple cout
Definition: gather_cfg.py:41
string s
Definition: asciidump.py:422