Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#851 make molecule sgroups movable #852

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/c/indigo/src/indigo_molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3174,8 +3174,8 @@ CEXPORT int indigoAddSGroupAttachmentPoint(int sgroup, int aidx, int lvidx, cons
INDIGO_BEGIN
{
Superatom& sup = IndigoSuperatom::cast(self.getObject(sgroup)).get();
int ap_idx = sup.attachment_points.add();
Superatom::_AttachmentPoint& ap = sup.attachment_points.at(ap_idx);
int ap_idx = sup.getAttachmentPoints().add();
Superatom::_AttachmentPoint& ap = sup.getAttachmentPoints().at(ap_idx);
ap.aidx = aidx;
ap.lvidx = lvidx;
ap.apid.readString(apid, true);
Expand All @@ -3189,7 +3189,7 @@ CEXPORT int indigoDeleteSGroupAttachmentPoint(int sgroup, int ap_idx)
INDIGO_BEGIN
{
Superatom& sup = IndigoSuperatom::cast(self.getObject(sgroup)).get();
sup.attachment_points.remove(ap_idx);
sup.getAttachmentPoints().remove(ap_idx);
return 1;
}
INDIGO_END(-1);
Expand Down
14 changes: 9 additions & 5 deletions core/indigo-core/common/base_cpp/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ namespace indigo
{
}

Array(Array&& other) : _reserved(other._reserved), _length(other._length), _array(other._array)
Array(Array&& other) noexcept : Array()
{
other._array = nullptr;
other._length = 0;
other._reserved = 0;
swap(other);
}

~Array()
Expand All @@ -62,6 +60,12 @@ namespace indigo
}
}

Array& operator=(Array&& src) noexcept
{
swap(src);
return *this;
}

void clear()
{
_length = 0;
Expand Down Expand Up @@ -358,7 +362,7 @@ namespace indigo
_length = newsize;
}

void swap(Array<T>& other)
void swap(Array<T>& other) noexcept
{
std::swap(_array, other._array);
std::swap(_reserved, other._reserved);
Expand Down
2 changes: 1 addition & 1 deletion core/indigo-core/common/base_cpp/string_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int StringPool::add(int size)
return _add(0, size);
}

int StringPool::add(Array<char>& str)
int StringPool::add(const Array<char>& str)
{
return _add(str.ptr(), str.size());
}
Expand Down
2 changes: 1 addition & 1 deletion core/indigo-core/common/base_cpp/string_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace indigo
~StringPool();

int add(const char* str);
int add(Array<char>& str);
int add(const Array<char>& str);
int add(int size);
void remove(int idx);
int size() const;
Expand Down
2 changes: 1 addition & 1 deletion core/indigo-core/molecule/base_molecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ namespace indigo
int getTemplateAtomAttachmentPoint(int atom_idx, int order);
void getTemplateAtomAttachmentPointId(int atom_idx, int order, Array<char>& apid);
int getTemplateAtomAttachmentPointsCount(int atom_idx);
int getTemplateAtomAttachmentPointById(int atom_idx, Array<char>& att_id);
int getTemplateAtomAttachmentPointById(int atom_idx, const Array<char>& att_id);

void addAttachmentPoint(int order, int atom_index);

Expand Down
58 changes: 39 additions & 19 deletions core/indigo-core/molecule/molecule_sgroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef __molecule_sgroups__
#define __molecule_sgroups__

#include <memory>

#include "base_cpp/array.h"
#include "base_cpp/obj_pool.h"
#include "base_cpp/ptr_pool.h"
Expand Down Expand Up @@ -99,7 +101,13 @@ namespace indigo
};

SGroup();
virtual ~SGroup();
SGroup(const SGroup&) = delete;
SGroup(SGroup&&) noexcept = default;

virtual ~SGroup() = default;

SGroup& operator=(const SGroup&) = delete;
SGroup& operator=(SGroup&&) noexcept = default;

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

static const char* typeToString(int sg_type);
static int getType(const char* sg_type);

private:
SGroup(const SGroup&);
};

class DLLEXPORT DataSGroup : public SGroup
{
public:
DataSGroup();
~DataSGroup() override;
DataSGroup(const DataSGroup&) = delete;
DataSGroup(DataSGroup&&) noexcept = default;

DataSGroup& operator=(const DataSGroup&) = delete;
DataSGroup& operator=(DataSGroup&&) noexcept = default;

Array<char> description; // SDT in Molfile format (filed units or format)
Array<char> name; // SDT in Molfile format (field name)
Expand All @@ -140,15 +149,17 @@ namespace indigo
int num_chars; // number of characters
int dasp_pos;
char tag; // tag
private:
DataSGroup(const DataSGroup&);
};

class DLLEXPORT Superatom : public SGroup
{
public:
Superatom();
~Superatom() override;
Superatom(const Superatom&) = delete;
Superatom(Superatom&&) noexcept = default;

Superatom& operator=(const Superatom&) = delete;
Superatom& operator=(Superatom&&) noexcept = default;

Array<char> subscript; // SMT in Molfile format
Array<char> sa_class; // SCL in Molfile format
Expand All @@ -163,7 +174,9 @@ namespace indigo
int lvidx;
Array<char> apid;
};
ObjPool<_AttachmentPoint> attachment_points; // SAP in Molfile format
const ObjPool<_AttachmentPoint>& getAttachmentPoints() const;
ObjPool<_AttachmentPoint>& getAttachmentPoints();
bool hasAttachmentPoints() const;

struct _BondConnection
{
Expand All @@ -173,40 +186,47 @@ namespace indigo
Array<_BondConnection> bond_connections; // SBV in Molfile format

private:
Superatom(const Superatom&);
mutable std::unique_ptr<ObjPool<_AttachmentPoint>> _attachment_points; // SAP in Molfile format
};

class DLLEXPORT RepeatingUnit : public SGroup
{
public:
RepeatingUnit();
~RepeatingUnit() override;
RepeatingUnit(const RepeatingUnit&) = delete;
RepeatingUnit(RepeatingUnit&&) noexcept = default;

RepeatingUnit& operator=(const RepeatingUnit&) = delete;
RepeatingUnit& operator=(RepeatingUnit&&) noexcept = default;

int connectivity;
Array<char> subscript; // SMT in Molfile format
private:
RepeatingUnit(const RepeatingUnit&);
};

class DLLEXPORT MultipleGroup : public SGroup
{
public:
MultipleGroup();
~MultipleGroup() override;
MultipleGroup(const MultipleGroup&) = delete;
MultipleGroup(MultipleGroup&&) noexcept = default;

MultipleGroup& operator=(const MultipleGroup&) = delete;
MultipleGroup& operator=(MultipleGroup&&) noexcept = default;

Array<int> parent_atoms;
int multiplier;

private:
MultipleGroup(const MultipleGroup&);
};

class Tree;
class DLLEXPORT MoleculeSGroups
{
public:
MoleculeSGroups();
~MoleculeSGroups();
MoleculeSGroups(const MoleculeSGroups&) = delete;
MoleculeSGroups(MoleculeSGroups&&) noexcept = default;

MoleculeSGroups& operator=(const MoleculeSGroups&) = delete;
MoleculeSGroups& operator=(MoleculeSGroups&&) noexcept = default;

DECL_ERROR;

Expand Down Expand Up @@ -248,7 +268,7 @@ namespace indigo
void registerUnfoldedHydrogen(int idx, int new_h_idx);

protected:
PtrPool<SGroup> _sgroups;
std::unique_ptr<PtrPool<SGroup>> _sgroups;

private:
int _findSGroupById(int id);
Expand Down
Loading