Skip to content

Commit d37c17c

Browse files
Aliaksander StsepaniukAliaksander Stsepaniuk
Aliaksander Stsepaniuk
authored and
Aliaksander Stsepaniuk
committed
Issue #851 Make molecule sgroups classes movable
1 parent f65bdcf commit d37c17c

File tree

9 files changed

+203
-173
lines changed

9 files changed

+203
-173
lines changed

api/c/indigo/src/indigo_molecule.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -3174,8 +3174,8 @@ CEXPORT int indigoAddSGroupAttachmentPoint(int sgroup, int aidx, int lvidx, cons
31743174
INDIGO_BEGIN
31753175
{
31763176
Superatom& sup = IndigoSuperatom::cast(self.getObject(sgroup)).get();
3177-
int ap_idx = sup.attachment_points.add();
3178-
Superatom::_AttachmentPoint& ap = sup.attachment_points.at(ap_idx);
3177+
int ap_idx = sup.getAttachmentPoints().add();
3178+
Superatom::_AttachmentPoint& ap = sup.getAttachmentPoints().at(ap_idx);
31793179
ap.aidx = aidx;
31803180
ap.lvidx = lvidx;
31813181
ap.apid.readString(apid, true);
@@ -3189,7 +3189,7 @@ CEXPORT int indigoDeleteSGroupAttachmentPoint(int sgroup, int ap_idx)
31893189
INDIGO_BEGIN
31903190
{
31913191
Superatom& sup = IndigoSuperatom::cast(self.getObject(sgroup)).get();
3192-
sup.attachment_points.remove(ap_idx);
3192+
sup.getAttachmentPoints().remove(ap_idx);
31933193
return 1;
31943194
}
31953195
INDIGO_END(-1);

core/indigo-core/common/base_cpp/string_pool.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int StringPool::add(int size)
6565
return _add(0, size);
6666
}
6767

68-
int StringPool::add(Array<char>& str)
68+
int StringPool::add(const Array<char>& str)
6969
{
7070
return _add(str.ptr(), str.size());
7171
}

core/indigo-core/common/base_cpp/string_pool.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace indigo
3939
~StringPool();
4040

4141
int add(const char* str);
42-
int add(Array<char>& str);
42+
int add(const Array<char>& str);
4343
int add(int size);
4444
void remove(int idx);
4545
int size() const;

core/indigo-core/molecule/base_molecule.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ namespace indigo
176176
int getTemplateAtomAttachmentPoint(int atom_idx, int order);
177177
void getTemplateAtomAttachmentPointId(int atom_idx, int order, Array<char>& apid);
178178
int getTemplateAtomAttachmentPointsCount(int atom_idx);
179-
int getTemplateAtomAttachmentPointById(int atom_idx, Array<char>& att_id);
179+
int getTemplateAtomAttachmentPointById(int atom_idx, const Array<char>& att_id);
180180

181181
void addAttachmentPoint(int order, int atom_index);
182182

core/indigo-core/molecule/molecule_sgroups.h

+39-19
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#ifndef __molecule_sgroups__
2020
#define __molecule_sgroups__
2121

22+
#include <memory>
23+
2224
#include "base_cpp/array.h"
2325
#include "base_cpp/obj_pool.h"
2426
#include "base_cpp/ptr_pool.h"
@@ -99,7 +101,13 @@ namespace indigo
99101
};
100102

101103
SGroup();
102-
virtual ~SGroup();
104+
SGroup(const SGroup&) = delete;
105+
SGroup(SGroup&&) noexcept = default;
106+
107+
virtual ~SGroup() = default;
108+
109+
SGroup& operator=(const SGroup&) = delete;
110+
SGroup& operator=(SGroup&&) noexcept = default;
103111

104112
int sgroup_type; // group type, represnted with STY in Molfile format
105113
int sgroup_subtype; // group subtype, represnted with SST in Molfile format
@@ -116,16 +124,17 @@ namespace indigo
116124

117125
static const char* typeToString(int sg_type);
118126
static int getType(const char* sg_type);
119-
120-
private:
121-
SGroup(const SGroup&);
122127
};
123128

124129
class DLLEXPORT DataSGroup : public SGroup
125130
{
126131
public:
127132
DataSGroup();
128-
~DataSGroup() override;
133+
DataSGroup(const DataSGroup&) = delete;
134+
DataSGroup(DataSGroup&&) noexcept = default;
135+
136+
DataSGroup& operator=(const DataSGroup&) = delete;
137+
DataSGroup& operator=(DataSGroup&&) noexcept = default;
129138

130139
Array<char> description; // SDT in Molfile format (filed units or format)
131140
Array<char> name; // SDT in Molfile format (field name)
@@ -140,15 +149,17 @@ namespace indigo
140149
int num_chars; // number of characters
141150
int dasp_pos;
142151
char tag; // tag
143-
private:
144-
DataSGroup(const DataSGroup&);
145152
};
146153

147154
class DLLEXPORT Superatom : public SGroup
148155
{
149156
public:
150157
Superatom();
151-
~Superatom() override;
158+
Superatom(const Superatom&) = delete;
159+
Superatom(Superatom&&) noexcept = default;
160+
161+
Superatom& operator=(const Superatom&) = delete;
162+
Superatom& operator=(Superatom&&) noexcept = default;
152163

153164
Array<char> subscript; // SMT in Molfile format
154165
Array<char> sa_class; // SCL in Molfile format
@@ -163,7 +174,9 @@ namespace indigo
163174
int lvidx;
164175
Array<char> apid;
165176
};
166-
ObjPool<_AttachmentPoint> attachment_points; // SAP in Molfile format
177+
const ObjPool<_AttachmentPoint>& getAttachmentPoints() const;
178+
ObjPool<_AttachmentPoint>& getAttachmentPoints();
179+
bool hasAttachmentPoints() const;
167180

168181
struct _BondConnection
169182
{
@@ -173,40 +186,47 @@ namespace indigo
173186
Array<_BondConnection> bond_connections; // SBV in Molfile format
174187

175188
private:
176-
Superatom(const Superatom&);
189+
mutable std::unique_ptr<ObjPool<_AttachmentPoint>> _attachment_points; // SAP in Molfile format
177190
};
178191

179192
class DLLEXPORT RepeatingUnit : public SGroup
180193
{
181194
public:
182195
RepeatingUnit();
183-
~RepeatingUnit() override;
196+
RepeatingUnit(const RepeatingUnit&) = delete;
197+
RepeatingUnit(RepeatingUnit&&) noexcept = default;
198+
199+
RepeatingUnit& operator=(const RepeatingUnit&) = delete;
200+
RepeatingUnit& operator=(RepeatingUnit&&) noexcept = default;
184201

185202
int connectivity;
186203
Array<char> subscript; // SMT in Molfile format
187-
private:
188-
RepeatingUnit(const RepeatingUnit&);
189204
};
190205

191206
class DLLEXPORT MultipleGroup : public SGroup
192207
{
193208
public:
194209
MultipleGroup();
195-
~MultipleGroup() override;
210+
MultipleGroup(const MultipleGroup&) = delete;
211+
MultipleGroup(MultipleGroup&&) noexcept = default;
212+
213+
MultipleGroup& operator=(const MultipleGroup&) = delete;
214+
MultipleGroup& operator=(MultipleGroup&&) noexcept = default;
196215

197216
Array<int> parent_atoms;
198217
int multiplier;
199-
200-
private:
201-
MultipleGroup(const MultipleGroup&);
202218
};
203219

204220
class Tree;
205221
class DLLEXPORT MoleculeSGroups
206222
{
207223
public:
208224
MoleculeSGroups();
209-
~MoleculeSGroups();
225+
MoleculeSGroups(const MoleculeSGroups&) = delete;
226+
MoleculeSGroups(MoleculeSGroups&&) noexcept = default;
227+
228+
MoleculeSGroups& operator=(const MoleculeSGroups&) = delete;
229+
MoleculeSGroups& operator=(MoleculeSGroups&&) noexcept = default;
210230

211231
DECL_ERROR;
212232

@@ -248,7 +268,7 @@ namespace indigo
248268
void registerUnfoldedHydrogen(int idx, int new_h_idx);
249269

250270
protected:
251-
PtrPool<SGroup> _sgroups;
271+
std::unique_ptr<PtrPool<SGroup>> _sgroups;
252272

253273
private:
254274
int _findSGroupById(int id);

0 commit comments

Comments
 (0)