44constexpr int SIZE = 65 ;
55
66#include < algorithm>
7+ #include < boost/algorithm/string.hpp>
78#include < exception>
89#include < list>
910#include < memory>
@@ -12,8 +13,6 @@ constexpr int SIZE = 65;
1213#include < unordered_map>
1314#include < vector>
1415
15- #include < boost/algorithm/string.hpp>
16-
1716class Thing ;
1817
1918bool IsNumber (const std::string& s);
@@ -22,58 +21,58 @@ std::vector<std::string> TokenizeString(const std::string& s);
2221
2322enum class Color
2423{
25- None,
26- White,
27- Red,
28- Green,
29- Blue,
30- Yellow,
31- Cyan,
32- Magenta,
24+ None,
25+ White,
26+ Red,
27+ Green,
28+ Blue,
29+ Yellow,
30+ Cyan,
31+ Magenta,
3332};
3433
3534struct Event
3635{
37- enum class Type
38- {
39- Invalid,
40- Say,
41- Move,
42- Use,
43- Do,
44- Whisper,
45- Chat,
46- Message,
47- Buy,
48- Info,
49- Ask,
50- Help,
51- Inspect,
52- Greet,
53- Attack,
54- Kill,
55- Death,
56- Enter,
57- Leave,
58- Gain,
59- Look,
60- Gain_Quest,
61- Register,
62- };
63-
64- std::string verb;
65- std::string target;
66- std::string object;
67- std::string extra;
68- std::string payload;
69-
70- Type type;
36+ enum class Type
37+ {
38+ Invalid,
39+ Say,
40+ Move,
41+ Use,
42+ Do,
43+ Whisper,
44+ Chat,
45+ Message,
46+ Buy,
47+ Info,
48+ Ask,
49+ Help,
50+ Inspect,
51+ Greet,
52+ Attack,
53+ Kill,
54+ Death,
55+ Enter,
56+ Leave,
57+ Gain,
58+ Look,
59+ Gain_Quest,
60+ Register,
61+ };
62+
63+ std::string verb;
64+ std::string target;
65+ std::string object;
66+ std::string extra;
67+ std::string payload;
68+
69+ Type type;
7170};
7271
7372const std::string GetColor (Color color_code);
7473
7574const std::string HeaderString (const std::string& s, const std::string& title, const char h = ' ' ,
76- int size = SIZE);
75+ int size = SIZE);
7776
7877const std::string ColorString (const std::string& s, Color color_code);
7978
@@ -82,101 +81,101 @@ const std::string CenteredString(const std::string& s, int size = SIZE);
8281template <typename T> const std::shared_ptr<Thing> GetSmartPtr (const T& container, Thing* t_ptr);
8382
8483const std::shared_ptr<Thing> FindByName (std::vector<std::shared_ptr<Thing>>& container,
85- const std::string& s);
84+ const std::string& s);
8685
8786template <typename T, typename F>
8887const std::string BlockListStringSimple (const T& c, const char b, F f, int step = 3 ,
89- int size = SIZE)
88+ int size = SIZE)
9089{
91- int i = 0 ;
90+ int i = 0 ;
9291
93- std::stringstream ss;
92+ std::stringstream ss;
9493
95- for (auto & t : c)
96- {
97- ss << b << (b ? ' ' : ' \0 ' ) << f (t);
94+ for (auto & t : c)
95+ {
96+ ss << b << (b ? ' ' : ' \0 ' ) << f (t);
9897
99- ss << ' \t ' ;
98+ ss << ' \t ' ;
10099
101- i++;
100+ i++;
102101
103- if (i % step == 0 )
104- ss << ' \n ' ;
105- }
102+ if (i % step == 0 )
103+ ss << ' \n ' ;
104+ }
106105
107- return ss.str ();
106+ return ss.str ();
108107}
109108
110109template <typename T, typename F>
111110const std::string BlockListString (const T& c, const char b, F f, int step = 3 , int size = SIZE)
112111{
113- // Group identical Things
112+ // Group identical Things
114113
115- std::unordered_map<std::string, int > m;
114+ std::unordered_map<std::string, int > m;
116115
117- for (auto & t : c)
118- {
119- m[f (t)] += 1 ;
120- }
116+ for (auto & t : c)
117+ {
118+ m[f (t)] += 1 ;
119+ }
121120
122- std::stringstream ss;
121+ std::stringstream ss;
123122
124- int i = 0 ;
123+ int i = 0 ;
125124
126- for (auto [name, n] : m)
127- {
125+ for (auto [name, n] : m)
126+ {
128127
129- ss << b << ' ' << name;
128+ ss << b << ' ' << name;
130129
131- if (n > 1 )
132- ss << " (" << n << ' )' ;
130+ if (n > 1 )
131+ ss << " (" << n << ' )' ;
133132
134- ss << ' \t ' ;
133+ ss << ' \t ' ;
135134
136- i++;
135+ i++;
137136
138- if (i % step == 0 )
139- ss << ' \n ' ;
140- }
137+ if (i % step == 0 )
138+ ss << ' \n ' ;
139+ }
141140
142- return ss.str ();
141+ return ss.str ();
143142}
144143
145144const std::string BarString (float filled, int max_size = SIZE, const char f = ' :' ,
146- const char lb = ' [' , const char rb = ' ]' );
145+ const char lb = ' [' , const char rb = ' ]' );
147146
148147template <typename T, typename F>
149148const std::string VerticalListString (const T& c, const char b, F f, const char sep = 0 ,
150- int size = SIZE)
149+ int size = SIZE)
151150{
152- std::stringstream ss;
151+ std::stringstream ss;
153152
154- for (auto it = c.begin (); it != c.end (); ++it)
155- {
156- ss << b << ' ' << f (*it) << ' \n ' ;
153+ for (auto it = c.begin (); it != c.end (); ++it)
154+ {
155+ ss << b << ' ' << f (*it) << ' \n ' ;
157156
158- if (size && sep && it != c.end () - 1 )
159- ss << std::string (size, sep) << ' \n ' ;
160- }
157+ if (size && sep && it != c.end () - 1 )
158+ ss << std::string (size, sep) << ' \n ' ;
159+ }
161160
162- return ss.str ();
161+ return ss.str ();
163162}
164163
165164template <typename T>
166165const std::string VerticalListString (const T& c, const char b, const char sep = ' ' ,
167- int size = SIZE)
166+ int size = SIZE)
168167{
169- std::stringstream ss;
168+ std::stringstream ss;
170169
171- for (auto it = c.begin (); it != c.end (); ++it)
172- {
173- ss << b << ' ' << **it << ' \n ' ;
170+ for (auto it = c.begin (); it != c.end (); ++it)
171+ {
172+ ss << b << ' ' << **it << ' \n ' ;
174173
175- if (size && it != c.end () - 1 )
176- ss << std::string (size, sep) << ' \n ' ;
177- }
174+ if (size && it != c.end () - 1 )
175+ ss << std::string (size, sep) << ' \n ' ;
176+ }
178177
179- return ss.str ();
178+ return ss.str ();
180179}
181180
182181void HandleException (const std::shared_ptr<Thing>& t, std::exception& e);
0 commit comments