Open Babel  3.0
text.h
Go to the documentation of this file.
1 /**********************************************************************
2 text.h - Declaration and Implementation of OBText
3 
4 Copyright (C) 2008 by Chris Morley
5 
6 This file is part of the Open Babel project.
7 For more information, see <http://openbabel.org/>
8 
9 This program 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 version 2 of the License.
12 
13 This program 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 
19 #ifndef OB_TEXT_H
20 #define OB_TEXT_H
21 
22 #include <openbabel/babelconfig.h>
23 #include <openbabel/base.h>
24 
25 namespace OpenBabel
26 {
29 class OBText : public OBBase
30 {
31 private:
32  std::string txt;
33 public:
34  //Constructors
35  OBText(){}
36  OBText(const std::string& text) :txt(text) {}
37 
39  std::string GetText()const { return txt; }
40 
68  std::string GetText(std::string::size_type& pos, bool ToInsertOnly=false) const
69  {
70  std::string::size_type oldpos = pos;
71  std::string::size_type newpos = txt.find("OPENBABEL_INSERT", pos);
72  if(newpos== std::string::npos)//not found: return rest of txt
73  {
74  if(ToInsertOnly)
75  return("");
76  pos = 0;
77  return txt.substr(oldpos);
78  }
79 
80  newpos = txt.rfind('\n', newpos); //to end of previous line
81  pos = txt.find("\n", newpos+1)+1; //to past end of line, or 0
82  return txt.substr(oldpos, newpos-oldpos);
83  }
84 
85  void SetText(const std::string& text){ txt = text; }
86 };
87 
88 }//namespace
89 #endif //OB_TEXT_H
90 
OBText(const std::string &text)
Definition: text.h:36
An object containing just text.
Definition: text.h:29
std::string GetText(std::string::size_type &pos, bool ToInsertOnly=false) const
Definition: text.h:68
Base classes to build a graph.
void SetText(const std::string &text)
Definition: text.h:85
std::string GetText() const
Definition: text.h:39
OBText()
Definition: text.h:35
Base Class.
Definition: base.h:239
Global namespace for all Open Babel code.
Definition: alias.h:22