source.cc
Go to the documentation of this file.
1 #include "stage.hh"
2 using namespace Stg;
3 
4 const double FLAGSZ = 0.25;
5 
6 typedef struct {
7  unsigned int capacity;
8 } info_t;
9 
10 int Update(Model *mod, info_t *info)
11 {
12  if (mod->GetFlagCount() < info->capacity) {
13  // printf( "Source adding flag to model %s\n", mod->Token() );
14  mod->PushFlag(new Model::Flag(Color(1, 1, 0), FLAGSZ));
15  }
16  return 0; // run again
17 }
18 
19 void split(const std::string &text, const std::string &separators, std::vector<std::string> &words)
20 {
21  int n = text.length();
22  int start = text.find_first_not_of(separators);
23  while ((start >= 0) && (start < n)) {
24  int stop = text.find_first_of(separators, start);
25  if ((stop < 0) || (stop > n))
26  stop = n;
27  words.push_back(text.substr(start, stop - start));
28  start = text.find_first_not_of(separators, stop + 1);
29  }
30 }
31 
32 // Stage calls this when the model starts up
33 extern "C" int Init(Model *mod, CtrlArgs *args)
34 {
35  puts("Starting source controller");
36 
37  // tokenize the argument string into words
38  std::vector<std::string> words;
39  split(args->worldfile, std::string(" \t"), words);
40 
41  // expect a capacity as the 1th argument
42  assert(words.size() == 2);
43  assert(words[1].size() > 0);
44 
45  info_t *info = new info_t;
46  info->capacity = atoi(words[1].c_str());
47 
48  printf("Source Capacity: %u\n", info->capacity);
49 
51  mod->Subscribe();
52  return 0; // ok
53 }
Model class
Definition: stage.hh:1651
unsigned int GetFlagCount() const
Definition: stage.hh:2151
The Stage library uses its own namespace.
Definition: canvas.hh:8
const double FLAGSZ
Definition: source.cc:4
void Init(int *argc, char **argv[])
Definition: stage.cc:17
int(* model_callback_t)(Model *mod, void *user)
Definition: stage.hh:540
void split(const std::string &text, const std::string &separators, std::vector< std::string > &words)
Definition: source.cc:19
void AddCallback(callback_type_t type, model_callback_t cb, void *user)
int Update(Model *mod, info_t *info)
Definition: source.cc:10
void PushFlag(Flag *flag)
Definition: model.cc:339
void Subscribe()
Definition: model.cc:516
Definition: source.cc:6
std::string worldfile
Definition: stage.hh:755
unsigned int capacity
Definition: source.cc:7


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Mon Feb 28 2022 23:48:56