Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
serialize_pose.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file
11 /// @brief
12 /// @author will sheffler
13 
14 #ifndef INCLUDED_core_io_serialization_serialize_pose_hh
15 #define INCLUDED_core_io_serialization_serialize_pose_hh
16 
17 #include <core/pose/Pose.fwd.hh>
18 
19 #include <core/types.hh>
20 // AUTO-REMOVED #include <utility/vector1.hh>
21 
22 #include <cstring>
23 // AUTO-REMOVED #include <string>
24 #include <vector>
25 
26 #include <utility/vector1.hh>
27 
28 
29 namespace core {
30 namespace io {
31 namespace serialization {
32 
33  struct BUFFER
34  {
35  BUFFER(size_t size) : start_(0),end_(0),size_(size),ownbuf_(true) {
36  buf_ = new char[size_];
37  }
38  BUFFER(char * buf, size_t size) :
39  buf_(buf),start_(0),end_(0),size_(size),ownbuf_(false) { }
40  ~BUFFER() {
41  if(ownbuf_) delete buf_;
42  }
43  int write(char * x, size_t nchar) {
44  if ( end_+nchar >= size_ ) return -1;
45  // strncpy(buf_+end_,x,nchar);
46  memcpy(buf_+end_,x,nchar);
47  end_ += nchar;
48  return 1;
49  }
50  int read(char * out_buf, size_t nchar) {
51  //if ( start_+nchar > end_ ) return -1;
52  if ( start_+nchar >= size_ ) return -2;
53  // strncpy(out_buf,buf_+start_,nchar);
54  memcpy(out_buf,buf_+start_,nchar);
55  start_ += nchar;
56  return 1;
57  }
58  private:
59  char *buf_;
60  size_t start_,end_,size_;
61  bool ownbuf_;
62  };
63 
64  // stuff from interactive/util/binary_file.hh/cc
65  void write_binary(char x, BUFFER & buf);
66  void read_binary(char & x, BUFFER & buf);
67  void write_binary(bool x, BUFFER & buf);
68  void read_binary(bool & x, BUFFER & buf);
69  void write_binary(float x, BUFFER & buf);
70  void read_binary(float & x, BUFFER & buf);
71  void write_binary(double x, BUFFER & buf);
72  void read_binary(double & x, BUFFER & buf);
73  void write_binary(unsigned int x, BUFFER & buf);
74  void read_binary(unsigned int & x, BUFFER & buf);
75 
76  /// Read/write simple structure to a file.
77  void write_binary(const utility::vector1_bool & x, BUFFER & buf);
78  void read_binary( utility::vector1_bool & x, BUFFER & buf);
79  void write_binary(const std::vector<std::string> & x, BUFFER & buf);
80  void read_binary( std::vector<std::string> & x, BUFFER & buf);
81  void write_binary( const std::string & x, BUFFER & buf);
82  void read_binary( std::string & x, BUFFER & buf);
83  void write_binary( const core::Vector & x, BUFFER & buf);
84  void read_binary( core::Vector & x, BUFFER & buf);
85 
86  /// Utility read/write.
87  void check_binary_unsigned_int(unsigned int x, BUFFER & buf);
88  void write_binary_chars(const char *x, BUFFER & buf);
89  void check_binary_chars(const char *x, BUFFER & buf);
90 
91  /// Read/Write a pose to a file
92  void write_binary(const core::pose::Pose & pose, BUFFER & buf);
93  void read_binary(core::pose::Pose & pose, BUFFER & buf);
94 
95 } // serialization
96 } // io
97 } // core
98 
99 #endif // INCLUDED_core_io_serialization_serialize_pose_HH