Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DT_RespTable.cpp « src « solid « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 20fbfc06aac5372a9e644b3699be64f57a7eff5e (plain)
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
 * SOLID - Software Library for Interference Detection
 * 
 * Copyright (C) 2001-2003  Dtecta.  All rights reserved.
 *
 * This library may be distributed under the terms of the Q Public License
 * (QPL) as defined by Trolltech AS of Norway and appearing in the file
 * LICENSE.QPL included in the packaging of this file.
 *
 * This library may be distributed and/or modified under the terms of the
 * GNU General Public License (GPL) version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Commercial use or any other use of this library not covered by either 
 * the QPL or the GPL requires an additional license from Dtecta. 
 * Please contact info@dtecta.com for enquiries about the terms of commercial
 * use of this library.
 */

#include "DT_RespTable.h"

#include <assert.h>

DT_ResponseList DT_RespTable::g_emptyResponseList;

DT_RespTable::~DT_RespTable()
{
	DT_ResponseClass i;
	for (i = 0; i < m_responseClass; ++i) 
	{
		delete [] m_table[i];
	}
}

DT_ResponseClass DT_RespTable::genResponseClass()
{
	DT_ResponseClass newClass = m_responseClass++;
	DT_ResponseList *newList = new DT_ResponseList[m_responseClass];
	assert(newList);
	m_table.push_back(newList);
	m_singleList.resize(m_responseClass);
	DT_ResponseClass i;
	for (i = 0; i < m_responseClass; ++i) 
	{
		newList[i].append(m_default);
		newList[i].append(m_singleList[i]);
	}
	return newClass;
}

void DT_RespTable::setResponseClass(void *object, 
									DT_ResponseClass responseClass) 
{
	assert(responseClass < m_responseClass);
	m_objectMap[object] = responseClass;
}

DT_ResponseClass DT_RespTable::getResponseClass(void *object) const
{
	T_ObjectMap::const_iterator it = m_objectMap.find(object);
	assert(it != m_objectMap.end());
	return (*it).second;
}

void DT_RespTable::clearResponseClass(void *object) 
{
	m_objectMap.erase(object);
}

const DT_ResponseList& DT_RespTable::find(void *object1, void *object2) const
{
	T_ObjectMap::const_iterator it = m_objectMap.find(object1);
	if (it != m_objectMap.end()) 
	{
		DT_ResponseClass responseClass1 = (*it).second;
		it = m_objectMap.find(object2);
		if (it != m_objectMap.end()) 
		{
			DT_ResponseClass responseClass2 = (*it).second;
			if (responseClass1 < responseClass2) 
			{
				std::swap(responseClass1, responseClass2);
			}
			return m_table[responseClass1][responseClass2];
		}
	}
	return g_emptyResponseList;
}

void DT_RespTable::addDefault(const DT_Response& response)
{
	m_default.addResponse(response);
	DT_ResponseClass i;
	for (i = 0; i < m_responseClass; ++i) 
	{
		DT_ResponseClass j;
		for (j = 0; j <= i; ++j) 
		{
			m_table[i][j].addResponse(response);
		}
	}
}

void DT_RespTable::removeDefault(const DT_Response& response)
{
	m_default.removeResponse(response);
	DT_ResponseClass i;
	for (i = 0; i < m_responseClass; ++i) 
	{
		DT_ResponseClass j;
		for (j = 0; j <= i; ++j) 
		{
			m_table[i][j].removeResponse(response);
		}
	}
}

void DT_RespTable::addSingle(DT_ResponseClass responseClass, 
							 const DT_Response& response)
{	
	assert(responseClass < m_responseClass);
	m_singleList[responseClass].addResponse(response);
	DT_ResponseClass j;
	for (j = 0; j < responseClass; ++j) 
	{
		m_table[responseClass][j].addResponse(response);
	}
	
	DT_ResponseClass i;
	for (i = responseClass; i < m_responseClass; ++i) 
	{
		m_table[i][responseClass].addResponse(response);
	}
}

void DT_RespTable::removeSingle(DT_ResponseClass responseClass, 
								const DT_Response& response)
{	
	assert(responseClass < m_responseClass);
	m_singleList[responseClass].removeResponse(response);
	DT_ResponseClass j;
	for (j = 0; j < responseClass; ++j) 
	{
		m_table[responseClass][j].removeResponse(response);
	}
	
	DT_ResponseClass i;
	for (i = responseClass; i < m_responseClass; ++i) 
	{
		m_table[i][responseClass].removeResponse(response);
	}
}

void DT_RespTable::addPair(DT_ResponseClass responseClass1,
						   DT_ResponseClass responseClass2, 
						   const DT_Response& response)
{
	assert(responseClass1 < m_responseClass);
	assert(responseClass2 < m_responseClass);
	if (responseClass1 < responseClass2) 
	{
		std::swap(responseClass1, responseClass2);
	}
	m_table[responseClass1][responseClass2].addResponse(response);
}


void DT_RespTable::removePair(DT_ResponseClass responseClass1,
							  DT_ResponseClass responseClass2, 
							  const DT_Response& response)
{
	assert(responseClass1 < m_responseClass);
	assert(responseClass2 < m_responseClass);
	if (responseClass1 < responseClass2) 
	{
		std::swap(responseClass1, responseClass2);
	}
	m_table[responseClass1][responseClass2].removeResponse(response);
}