File: Device.cpp

package info (click to toggle)
dolphin-emu 5.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 29,052 kB
  • sloc: cpp: 213,146; java: 6,252; asm: 2,277; xml: 1,998; ansic: 1,514; python: 462; sh: 279; pascal: 247; makefile: 124; perl: 97
file content (185 lines) | stat: -rw-r--r-- 3,261 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
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
185
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <sstream>
#include <string>

// For InputGateOn()
// This is a really bad layering violation, but it's the cleanest
// place I could find to put it.
#include "Core/ConfigManager.h"
#include "Core/Host.h"

#include "InputCommon/ControllerInterface/Device.h"

namespace ciface
{
namespace Core
{

//
// Device :: ~Device
//
// Destructor, delete all inputs/outputs on device destruction
//
Device::~Device()
{
	// delete inputs
	for (Device::Input* input : m_inputs)
		delete input;

	// delete outputs
	for (Device::Output* output: m_outputs)
		delete output;
}

void Device::AddInput(Device::Input* const i)
{
	m_inputs.push_back(i);
}

void Device::AddOutput(Device::Output* const o)
{
	m_outputs.push_back(o);
}

Device::Input* Device::FindInput(const std::string &name) const
{
	for (Input* input : m_inputs)
	{
		if (input->GetName() == name)
			return input;
	}

	return nullptr;
}

Device::Output* Device::FindOutput(const std::string &name) const
{
	for (Output* output : m_outputs)
	{
		if (output->GetName() == name)
			return output;
	}

	return nullptr;
}

bool Device::Control::InputGateOn()
{
	if (SConfig::GetInstance().m_BackgroundInput)
		return true;
	else if (Host_RendererHasFocus() || Host_UIHasFocus())
		return true;
	else
		return false;
}

//
// DeviceQualifier :: ToString
//
// Get string from a device qualifier / serialize
//
std::string DeviceQualifier::ToString() const
{
	if (source.empty() && (cid < 0) && name.empty())
		return "";

	std::ostringstream ss;
	ss << source << '/';
	if (cid > -1)
		ss << cid;
	ss << '/' << name;

	return ss.str();
}

//
// DeviceQualifier :: FromString
//
// Set a device qualifier from a string / unserialize
//
void DeviceQualifier::FromString(const std::string& str)
{
	std::istringstream ss(str);

	std::getline(ss, source = "", '/');

	// silly
	std::getline(ss, name, '/');
	std::istringstream(name) >> (cid = -1);

	std::getline(ss, name = "");
}

//
// DeviceQualifier :: FromDevice
//
// Set a device qualifier from a device
//
void DeviceQualifier::FromDevice(const Device* const dev)
{
	name = dev->GetName();
	cid = dev->GetId();
	source= dev->GetSource();
}

bool DeviceQualifier::operator==(const Device* const dev) const
{
	if (dev->GetId() == cid)
		if (dev->GetName() == name)
			if (dev->GetSource() == source)
				return true;

	return false;
}

bool DeviceQualifier::operator==(const DeviceQualifier& devq) const
{
	if (cid == devq.cid)
		if (name == devq.name)
			if (source == devq.source)
				return true;

	return false;
}

Device* DeviceContainer::FindDevice(const DeviceQualifier& devq) const
{
	for (Device* d : m_devices)
	{
		if (devq == d)
			return d;
	}

	return nullptr;
}

Device::Input* DeviceContainer::FindInput(const std::string& name, const Device* def_dev) const
{
	if (def_dev)
	{
		Device::Input* const inp = def_dev->FindInput(name);
		if (inp)
			return inp;
	}

	for (Device* d : m_devices)
	{
		Device::Input* const i = d->FindInput(name);

		if (i)
			return i;
	}

	return nullptr;
}

Device::Output* DeviceContainer::FindOutput(const std::string& name, const Device* def_dev) const
{
	return def_dev->FindOutput(name);
}

}
}