blob: fe655085018d6298f459c7dda61d97b3ab96bda9 (
plain) (
blame)
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
|
#include "Feedback.h"
#include "FileSystemUtilities.h"
#include <algorithm>
#include <iostream>
#include <vector>
std::vector<LoudMouth*> Lineup;
LoudMouth* Speaker = 0;
static void add(LoudMouth* MP)
{
std::vector<LoudMouth*>::iterator i =
std::find(Lineup.begin(),Lineup.end(),MP);
if (i == Lineup.end())
Lineup.push_back(MP);
}
static void request(LoudMouth* MP)
{
if (!Speaker)
Speaker = MP;
}
static void remove(LoudMouth* MP)
{
std::vector<LoudMouth*>::iterator idx =
std::find(Lineup.begin(),Lineup.end(),MP);
Lineup.erase(idx);
}
LoudMouth::LoudMouth()
: RequestWord(false), Finished(false)
{
}
LoudMouth::~LoudMouth()
{
}
void LoudMouth::whisper(const std::string& What)
{
add(this);
if (Speaker == this)
std::cout << What;
else
Speech += What;
}
void LoudMouth::whisperLn(const std::string& What)
{
whisper(What);
whisper(eolTextSequence());
}
void LoudMouth::say(const std::string& What)
{
RequestWord = true;
add(this);
request(this);
Speech += What;
if (Speaker == this)
{
std::cout << Speech;
Speech = "";
}
}
void LoudMouth::sayLn(const std::string& What)
{
say(What);
say(eolTextSequence());
}
void LoudMouth::yieldFloor()
{
Finished = true;
if (!Speaker || (Speaker == this))
{
std::cout << Speech;
Speech = "";
remove(this);
Speaker = 0;
for (unsigned int i=0; i<Lineup.size();)
{
if (Lineup[i]->Finished)
{
std::cout << Lineup[i]->Speech;
remove(Lineup[i]);
}
else
++i;
}
for (unsigned int i=0; i<Lineup.size(); ++i)
{
if (Lineup[i]->RequestWord)
{
request(Lineup[i]);
std::cout << Lineup[i]->Speech;
Lineup[i]->Speech = "";
break;
}
}
}
else if (Speech == "")
remove(this);
}
|