File: Compound.cpp

package info (click to toggle)
dyssol 1.5.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,204 kB
  • sloc: cpp: 53,870; sh: 85; python: 59; makefile: 11
file content (153 lines) | stat: -rw-r--r-- 4,486 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* Copyright (c) 2020, Dyssol Development Team. All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */

#include "Compound.h"
#include "StringFunctions.h"

CCompound::CCompound(const MDBDescriptors::constDescr& _constDescrs, const MDBDescriptors::tpdepDescr& _tpdDescrs, const std::string& _sUniqueCompoundKey /*= ""*/)
{
	m_sUniqueKey = _sUniqueCompoundKey.empty() ? StringFunctions::GenerateRandomKey() : _sUniqueCompoundKey;
	m_sName = "New compound";

	// add all const properties
	for (const auto& c : _constDescrs)
		m_vConstProperties.emplace_back(c.first, c.second.name, c.second.units, c.second.defaultValue);
	// add all TP-properties
	for (const auto& tp : _tpdDescrs)
		m_vTPProperties.emplace_back(tp.first, tp.second.name, tp.second.units, CCorrelation{ tp.second.defuaultType, tp.second.defaultParameters });
}

std::string CCompound::GetName() const
{
	return m_sName;
}

void CCompound::SetName(const std::string& _sName)
{
	m_sName = _sName;
}

std::string CCompound::GetKey() const
{
	return m_sUniqueKey;
}

void CCompound::SetKey(const std::string& _sKey)
{
	m_sUniqueKey = _sKey;
}

size_t CCompound::ConstPropertiesNumber() const
{
	return m_vConstProperties.size();
}

size_t CCompound::TPPropertiesNumber() const
{
	return m_vTPProperties.size();
}

bool CCompound::HasConstProperty(ECompoundConstProperties _nType) const
{
	for (const auto& c : m_vConstProperties)
		if (c.GetType() == _nType)
			return true;
	return false;
}

bool CCompound::HasTPProperty(ECompoundTPProperties _nType) const
{
	for (const auto& tp : m_vTPProperties)
		if (tp.GetType() == _nType)
			return true;
	return false;
}

bool CCompound::HasProperty(unsigned _nType) const
{
	return HasConstProperty(static_cast<ECompoundConstProperties>(_nType)) || HasTPProperty(static_cast<ECompoundTPProperties>(_nType));
}

void CCompound::AddConstProperty(ECompoundConstProperties _key, const std::string& _name, const std::wstring& _units, double _defaultValue)
{
	if (HasConstProperty(_key)) return;
	m_vConstProperties.emplace_back(_key, _name, _units, _defaultValue);
}

void CCompound::AddTPDepProperty(ECompoundTPProperties _key, const std::string& _name, const std::wstring& _units, double _defaultValue)
{
	if (HasTPProperty(_key)) return;
	m_vTPProperties.emplace_back(_key, _name, _units, CCorrelation{ ECorrelationTypes::CONSTANT, {_defaultValue} });
}

void CCompound::RemoveConstProperty(ECompoundConstProperties _key)
{
	for (size_t i = 0; i < m_vConstProperties.size(); ++i)
		if (m_vConstProperties[i].GetType() == _key)
			m_vConstProperties.erase(m_vConstProperties.begin() + i);
}

void CCompound::RemoveTPDepProperty(ECompoundTPProperties _key)
{
	for (size_t i = 0; i < m_vTPProperties.size(); ++i)
		if (m_vTPProperties[i].GetType() == _key)
			m_vTPProperties.erase(m_vTPProperties.begin() + i);
}

CConstProperty* CCompound::GetConstProperty(ECompoundConstProperties _nType)
{
	return const_cast<CConstProperty*>(static_cast<const CCompound&>(*this).GetConstProperty(_nType));
}

const CConstProperty* CCompound::GetConstProperty(ECompoundConstProperties _nType) const
{
	for (const auto& c : m_vConstProperties)
		if (c.GetType() == _nType)
			return &c;
	return nullptr;
}

CConstProperty* CCompound::GetConstPropertyByIndex(size_t _index)
{
	return const_cast<CConstProperty*>(static_cast<const CCompound&>(*this).GetConstPropertyByIndex(_index));
}

const CConstProperty* CCompound::GetConstPropertyByIndex(size_t _index) const
{
	if (_index >= m_vConstProperties.size()) return nullptr;
	return &m_vConstProperties[_index];
}

const std::vector<CConstProperty>& CCompound::GetConstProperties() const
{
	return m_vConstProperties;
}

CTPDProperty* CCompound::GetTPProperty(ECompoundTPProperties _nType)
{
	return const_cast<CTPDProperty*>(static_cast<const CCompound&>(*this).GetTPProperty(_nType));
}

const CTPDProperty* CCompound::GetTPProperty(ECompoundTPProperties _nType) const
{
	for (const auto& tp : m_vTPProperties)
		if (tp.GetType() == _nType)
			return &tp;
	return nullptr;
}

CTPDProperty* CCompound::GetTPPropertyByIndex(size_t _index)
{
	return const_cast<CTPDProperty*>(static_cast<const CCompound&>(*this).GetTPPropertyByIndex(_index));
}

const CTPDProperty* CCompound::GetTPPropertyByIndex(size_t _index) const
{
	if (_index >= m_vTPProperties.size())
		return nullptr;
	return &m_vTPProperties[_index];
}

const std::vector<CTPDProperty>& CCompound::GetTPProperties() const
{
	return m_vTPProperties;
}