Now you can download a copy of these docs so you can use them offline! Download now
SendableChooser.cpp
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2011. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #include "SmartDashboard/SendableChooser.h"
8 #include "networktables2/type/StringArray.h"
9 
10 #include <stdio.h>
11 
12 static const char *kDefault = "default";
13 static const char *kOptions = "options";
14 static const char *kSelected = "selected";
15 
16 SendableChooser::SendableChooser()
17 {
18  m_defaultChoice = "";
19 }
20 
27 void SendableChooser::AddObject(const char *name, void *object)
28 {
29  m_choices[name] = object;
30 }
31 
39 void SendableChooser::AddDefault(const char *name, void *object)
40 {
41  m_defaultChoice = name;
42  AddObject(name, object);
43 }
44 
51 {
52  std::string selected = m_table->GetString(kSelected, m_defaultChoice);
53  if (selected == "")
54  return NULL;
55  else
56  return m_choices[selected];
57 }
58 
60  StringArray keys;
61  m_table = subtable;
62  if (m_table != NULL) {
63  std::map<std::string, void *>::iterator iter;
64  for (iter = m_choices.begin(); iter != m_choices.end(); iter++) {
65  keys.add(iter->first);
66  }
67  m_table->PutValue(kOptions, keys);
68  m_table->PutString(kDefault, m_defaultChoice);
69  }
70 }
71 
73  return m_table;
74 }
75 
77  return "String Chooser";
78 }
Definition: ITable.h:26
virtual void InitTable(ITable *subtable)
virtual void PutValue(std::string key, ComplexData &value)=0
virtual std::string GetString(std::string key)=0
void AddDefault(const char *name, void *object)
virtual std::string GetSmartDashboardType()
virtual void PutString(std::string key, std::string value)=0
void AddObject(const char *name, void *object)
virtual ITable * GetTable()

Generated on Sat Apr 26 2014 12:26:45 for WPILibC++ by doxygen 1.8.6