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

DT_RespTable.h « src « solid « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9a17f5629375145e94e5bfe0a65dce2bc3a44454 (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
/*
 * 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.
 */

#ifndef DT_RESPTABLE_H
#define DT_RESPTABLE_H

#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include "GEN_MinMax.h"
#include "DT_Response.h"

class DT_ResponseList : public std::list<DT_Response> {
public:
    DT_ResponseList() : m_type(DT_NO_RESPONSE) {}

	DT_ResponseType getType() const { return m_type; }

    void addResponse(const DT_Response& response) 
	{
        if (response.getType() != DT_NO_RESPONSE) 
		{
            push_back(response);
            GEN_set_max(m_type, response.getType());
        }
    }

    void removeResponse(const DT_Response& response) 
	{
		iterator it = std::find(begin(), end(), response);
		if (it != end()) 
		{
			erase(it);
			m_type = DT_NO_RESPONSE;
			for (it = begin(); it != end(); ++it) 
			{
				GEN_set_max(m_type, (*it).getType());
			}
		}
    }
	
    void append(const DT_ResponseList& responseList) 
	{
        if (responseList.getType() != DT_NO_RESPONSE) 
		{
			const_iterator it;
			for (it = responseList.begin(); it != responseList.end(); ++it) 
			{
				addResponse(*it);
			}
		}
	}

    DT_Bool operator()(void *a, void *b, const DT_CollData *coll_data) const 
	{
		DT_Bool done = DT_CONTINUE;
		const_iterator it;
        for (it = begin(); !done && it != end(); ++it) 
		{
            done = (*it)(a, b, coll_data);
        }
		return done;
    }
    
private:
	DT_ResponseType    m_type;
};

class DT_RespTable {
private:
	typedef std::map<void *, DT_ResponseClass> T_ObjectMap; 
	typedef std::vector<DT_ResponseList *> T_PairTable;
	typedef std::vector<DT_ResponseList> T_SingleList;

public:
	DT_RespTable() : m_responseClass(0) {}

	~DT_RespTable();

	DT_ResponseClass genResponseClass();
	
	void setResponseClass(void *object, DT_ResponseClass responseClass);
	DT_ResponseClass getResponseClass(void *object) const;
	
	void clearResponseClass(void *object);
	
	const DT_ResponseList& find(void *object1, void *object2) const;

    void addDefault(const DT_Response& response); 
    void removeDefault(const DT_Response& response); 

    void addSingle(DT_ResponseClass responseClass, 
				   const DT_Response& response);
    void removeSingle(DT_ResponseClass responseClass, 
					  const DT_Response& response);
	
    void addPair(DT_ResponseClass responseClass1, 
				 DT_ResponseClass responseClass2, 
				 const DT_Response& response);
    void removePair(DT_ResponseClass responseClass1, 
					DT_ResponseClass responseClass2, 
					const DT_Response& response);

private:
	static DT_ResponseList g_emptyResponseList;

	T_ObjectMap      m_objectMap;
	DT_ResponseClass m_responseClass;
	T_PairTable      m_table;
	T_SingleList     m_singleList;
    DT_ResponseList  m_default;
};

#endif