Now you can download a copy of these docs so you can use them offline! Download now
SendableChooser.cpp
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2011. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #include "SmartDashboard/SendableChooser.h" 00008 00009 #include "NetworkTables/NetworkTable.h" 00010 #include <stdio.h> 00011 00012 static const char *kDefault = "default"; 00013 static const char *kCount = "count"; 00014 static const char *kSelected = "selected"; 00015 00016 SendableChooser::SendableChooser() 00017 { 00018 m_table = new NetworkTable(); 00019 m_count = 0; 00020 } 00021 00028 void SendableChooser::AddObject(const char *name, void *object) 00029 { 00030 std::pair<std::map<std::string, void *>::iterator, bool> ret = m_choices.insert(std::pair<std::string, void *>(name, object)); 00031 if (ret.second) 00032 { 00033 //idBuf is: 10 bytes for m_count and 1 for NULL term 00034 char idBuf[11]; 00035 snprintf(idBuf, 11, "%d", m_count); 00036 m_ids.insert(std::pair<void *, std::string>(object, idBuf)); 00037 m_table->PutString(idBuf, name); 00038 m_count++; 00039 m_table->PutInt(kCount, m_count); 00040 } 00041 else 00042 { 00043 std::string id = m_ids[ret.first->second]; 00044 ret.first->second = object; 00045 m_table->PutString(id, name); 00046 } 00047 } 00048 00056 void SendableChooser::AddDefault(const char *name, void *object) 00057 { 00058 m_defaultChoice = object; 00059 AddObject(name, object); 00060 m_table->PutString(kDefault, name); 00061 } 00062 00068 void *SendableChooser::GetSelected() 00069 { 00070 return m_table->ContainsKey(kSelected) ? m_choices[m_table->GetString(kSelected)] : m_defaultChoice; 00071 }
Generated on Thu Jan 12 2012 22:35:23 for WPILibC++ by
1.7.1