File: channellist.cpp

package info (click to toggle)
springlobby 0.267%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 13,780 kB
  • sloc: cpp: 79,169; ansic: 61,599; python: 927; sh: 735; perl: 238; xml: 52; makefile: 42; sed: 16
file content (68 lines) | stat: -rw-r--r-- 1,568 bytes parent folder | download
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
/* This file is part of the Springlobby (GPL v2 or later), see COPYING */

/**
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

TODO: remove all wx stuff & merge / move to

lsl/container/channellist.cpp

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
**/
#include "channellist.h"

#include <wx/log.h>
#include <iterator>
#include <stdexcept>

#include "channel.h"
#include "log.h"
#include "utils/conversion.h"

const UserList::user_map_t::size_type SEEKPOS_INVALID = UserList::user_map_t::size_type(-1);

ChannelList::ChannelList()
    : m_seek(m_chans.end())
    , m_seekpos(SEEKPOS_INVALID)
{
}

void ChannelList::AddChannel(Channel& channel)
{
	m_chans[channel.GetName()] = &channel;
	m_seekpos = SEEKPOS_INVALID;
}

void ChannelList::RemoveChannel(const std::string& name)
{
	m_chans.erase(name);
	m_seekpos = SEEKPOS_INVALID;
}

Channel& ChannelList::GetChannel(const std::string& name)
{
	channel_iter_t u = m_chans.find(name);
	ASSERT_LOGIC(u != m_chans.end(), stdprintf("ChannelList::GetChannel(\"%s\"): no such channel", name.c_str()));
	return *u->second;
}

Channel& ChannelList::GetChannel(channel_map_t::size_type index)
{
	if (m_seekpos == SEEKPOS_INVALID || m_seekpos > index) {
		m_seek = m_chans.begin();
		m_seekpos = 0;
	}
	std::advance(m_seek, index - m_seekpos);
	m_seekpos = index;
	return *m_seek->second;
}

bool ChannelList::ChannelExists(const std::string& name) const
{
	return m_chans.find(name) != m_chans.end();
}

channel_map_t::size_type ChannelList::GetNumChannels() const
{
	return m_chans.size();
}