WvStreams
wvstreamsdebugger.h
1/* -*- Mode: C++ -*- */
2#ifndef WVSTREAMSDEBUGGER_H
3#define WVSTREAMSDEBUGGER_H
4
5#include <map>
6
7#include "wverror.h"
8#include "wvstringlist.h"
9#include "wvtclstring.h"
10#include "wvtr1.h"
11
13{
14public:
15
16 // The callback type used to pass the results back to the application
17 // that calls WvStreamsDebugger::run. The application is allowed
18 // to consume the WvStringList of results.
19 typedef wv::function<void(WvStringParm, WvStringList&)> ResultCallback;
20
21 // Debugging commands are implemented through the following three
22 // callbacks:
23 // - InitCallback is optional and is used to allocate state
24 // for an instance of WvStreamsDebugger for the given command
25 // - RunCallback is required and is used to actually execute
26 // the command as a result of a call to WvStreamsDebugger::run
27 // - CleanupCallback is optional and is used to free state
28 // for an instance of WvStreamsDebugger for the given command
29 typedef wv::function<void*(WvStringParm)> InitCallback;
30 typedef wv::function<WvString(WvStringParm, WvStringList&,
31 ResultCallback, void*)> RunCallback;
32
33 typedef wv::function<void(WvStringParm, void*)> CleanupCallback;
34
35 // The WvStreamsDebugger::foreach function can be used to update
36 // state in every instance of WvStreamsDebugger for a given command.
37 typedef wv::function<void(WvStringParm, void*)> ForeachCallback;
38
39private:
40
41 struct Command
42 {
43 InitCallback init_cb;
44 RunCallback run_cb;
45 CleanupCallback cleanup_cb;
46
47 Command(InitCallback _init_cb, RunCallback _run_cb,
48 CleanupCallback _cleanup_cb)
49 {
50 init_cb = _init_cb;
51 run_cb = _run_cb;
52 cleanup_cb = _cleanup_cb;
53 }
54 };
55 typedef std::map<WvString, Command> CommandMap;
56 static CommandMap *commands;
57 typedef std::map<WvString, void*> CommandDataMap;
58 CommandDataMap command_data;
59
60 void *get_command_data(WvStringParm cmd, Command *command);
62
63public:
64
67
68 WvString run(WvStringParm cmd, WvStringList &args,
69 ResultCallback result_cb);
70
71 static bool add_command(WvStringParm cmd,
72 InitCallback init_cb,
73 RunCallback run_cb,
74 CleanupCallback cleanup_cb);
75
76 static bool foreach(WvStringParm cmd, ForeachCallback foreach_cb);
77
78private:
79
80 static WvString help_run_cb(WvStringParm cmd,
81 WvStringList &args,
82 ResultCallback result_cb, void *);
83};
84
85#endif
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition wvstring.h:94
This is a WvList of WvStrings, and is a really handy way to parse strings.
WvString is an implementation of a simple and efficient printable-string class.
Definition wvstring.h:330
Functions to handle "tcl-style" strings and lists.