LOOS  v2.3.2
pdb_remarks.cpp
1 /*
2  This file is part of LOOS.
3 
4  LOOS (Lightweight Object-Oriented Structure library)
5  Copyright (c) 2008, Tod D. Romo, Alan Grossfield
6  Department of Biochemistry and Biophysics
7  School of Medicine & Dentistry, University of Rochester
8 
9  This package (LOOS) is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation under version 3 of the License.
12 
13  This package is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 
23 
24 
25 #include <ios>
26 #include <sstream>
27 #include <iostream>
28 #include <iomanip>
29 
30 
31 #include <utils.hpp>
32 #include <pdb_remarks.hpp>
33 
34 
35 namespace loos {
36 
37  int Remarks::numberOf(void) const { return(remarks.size()); } // Compat with PERL
38  int Remarks::size(void) const { return(remarks.size()); }
39 
40  void Remarks::rangeCheck(const unsigned int i) const {
41  if (i >= remarks.size())
42  throw(std::range_error("Bad indices into remarks"));
43  }
44 
45 
46  std::string Remarks::get(const int i) const {
47  rangeCheck(i);
48  return(remarks[i]);
49  }
50 
51 
52  void Remarks::add(const std::string s) {
53  std::string t(s);
54  while (t.size() > 58) {
55  remarks.push_back(t.substr(0, 58));
56  t = t.substr(58);
57  }
58 
59  std::string u = sanitize(t);
60  remarks.push_back(sanitize(t));
61  }
62 
63  void Remarks::add(const std::vector<std::string>& s) {
64  for (std::vector<std::string>::const_iterator i = s.begin(); i != s.end(); ++i)
65  add(*i);
66  }
67 
68 
69  void Remarks::erase(const int i) {
70  rangeCheck(i);
71  remarks.erase(remarks.begin() + i);
72  }
73 
74 
75  std::string& Remarks::operator[](const int i) {
76  rangeCheck(i);
77  return(remarks[i]);
78  }
79 
80 
81  const std::string& Remarks::operator[](const int i) const {
82  rangeCheck(i);
83  return(remarks[i]);
84  }
85 
86 
87 
88  std::string Remarks::sanitize(const std::string s) const {
89  std::string t(s);
90  int n = s.size();
91 
92  if (n > 58)
93  t = s.substr(0, 58);
94  else if (n < 58)
95  t = s + std::string(58 - n, ' ');
96 
97  return(t);
98  }
99 
100 
101 
102  std::ostream& operator<<(std::ostream& os, const Remarks& r) {
103  std::vector<std::string>::const_iterator i;
104  int n = 1;
105 
106  for (i = r.remarks.begin(); i != r.remarks.end(); i++) {
107  std::string s("REMARK \n");
108  std::ostringstream ss;
109 
110  ss << std::setw(3) << std::setfill('0') << n++;
111  s.replace(7,3, ss.str());
112  s.replace(11,58, sanitizeString(*i));
113  os << s;
114  }
115 
116  return(os);
117  }
118 
119 }
void add(const std::string s)
Add a remark.
Definition: pdb_remarks.cpp:52
void erase(const int i)
Erase the ith remark.
Definition: pdb_remarks.cpp:69
Class for handling PDB Remarks.
Definition: pdb_remarks.hpp:41
Namespace for most things not already encapsulated within a class.
std::string & operator[](const int i)
Access the ith remark.
Definition: pdb_remarks.cpp:75
std::string sanitizeString(const std::string &s)
Removes internal newlines from string.
Definition: utils.cpp:378
std::string get(const int i) const
Access the ith remark.
Definition: pdb_remarks.cpp:46