-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPersonalityProgram.cpp
71 lines (56 loc) · 1.48 KB
/
PersonalityProgram.cpp
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
#include "PersonalityProgram.h"
PersonalityProgram::PersonalityProgram()
{
// Set up the information
m_name = "";
m_help = "";
m_output = "";
}
PersonalityProgram::~PersonalityProgram()
{
// Nothing. Your class may have to do some cleanup.
}
std::string PersonalityProgram::GetName()
{
return m_name;
}
std::string PersonalityProgram::GetHelp()
{
return m_help;
}
void PersonalityProgram::SetName(std::string name)
{
m_name = name;
}
void PersonalityProgram::SetHelp(std::string help)
{
m_help = help;
}
// Make sure that your printfs don't have more than
// 999 characters, or we'll have a problem.
void PersonalityProgram::Printf(const char *fmt, ...)
{
char buffer[1000]; // Buffer to store temporary result
// These invoke the magical data structures that allow
// us to accept a variable number of arguments.
va_list args;
va_start(args, fmt);
// We use a special form of sprintf to expand the
// format string with stuff provided in subsequent
// arguments.
vsprintf(buffer, fmt, args);
// Now we're done with the variable arguments.
va_end(args);
// Place output into nice, self-managing C++ string.
m_output += buffer;
}
std::string PersonalityProgram::Run(const std::vector<std::string> & args)
{
// Reset output
m_output = "";
// Run the main program (remember, you have to override this in your
// derived class)
RunMain(args);
// Return the result of any Printfs.
return m_output;
}