/src/openbabel/src/ops/addinindex.cpp
Line | Count | Source |
1 | | /********************************************************************** |
2 | | addinindex.cpp - Adds input index to title. |
3 | | |
4 | | Copyright(C) 2007 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 | | #include <openbabel/babelconfig.h> |
19 | | #include<openbabel/base.h> |
20 | | #include <sstream> |
21 | | #include<openbabel/op.h> |
22 | | #include<openbabel/obconversion.h> |
23 | | |
24 | | namespace OpenBabel |
25 | | { |
26 | | |
27 | | class OpAddInIndex : public OBOp |
28 | | { |
29 | | public: |
30 | 2 | OpAddInIndex(const char* ID) : OBOp(ID, false){}; |
31 | 0 | const char* Description() override { return |
32 | 0 | "Append input index to title\n" |
33 | 0 | "These are objects before filtering. Use AddOutIndex for objects after filtering\n"; } |
34 | | |
35 | 0 | bool WorksWith(OBBase* /*pOb*/) const override { return true; } // all objects |
36 | | bool Do(OBBase* pOb, const char*, OpMap*, OBConversion* pConv=nullptr) override; |
37 | | }; |
38 | | |
39 | | ///////////////////////////////////////////////////////////////// |
40 | | OpAddInIndex theOpAddInIndex("AddInIndex"); //Global instance |
41 | | |
42 | | ///////////////////////////////////////////////////////////////// |
43 | | bool OpAddInIndex::Do(OBBase* pOb, const char* /*OptionText*/, OpMap* /*pOptions*/, OBConversion* pConv) |
44 | 0 | { |
45 | 0 | int count = pConv->GetCount(); |
46 | 0 | if(count>=0) // add nothing unless Convert interface of OBConversion is being used |
47 | 0 | { |
48 | 0 | std::stringstream ss; |
49 | 0 | ss << pOb->GetTitle() << ' ' << count+1; |
50 | 0 | pOb->SetTitle(ss.str().c_str()); |
51 | 0 | } |
52 | 0 | return true; |
53 | 0 | } |
54 | | }//namespace |