Now you can download a copy of these docs so you can use them offline! Download now
NetworkTableSubListenerAdapter.cpp
1 /*
2  * NetworkTableSubListenerAdapter.cpp
3  *
4  * Created on: Oct 17, 2012
5  * Author: Mitchell Wills
6  */
7 
8 #include "networktables/NetworkTableSubListenerAdapter.h"
9 
10 
11 
18 NetworkTableSubListenerAdapter::NetworkTableSubListenerAdapter(std::string& _prefix, NetworkTable* _targetSource, ITableListener* _targetListener):
19  prefix(_prefix), targetSource(_targetSource), targetListener(_targetListener){}
20 
21 NetworkTableSubListenerAdapter::~NetworkTableSubListenerAdapter(){}
22 
23  void NetworkTableSubListenerAdapter::ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew) {//TODO use string cache
24  if(key.compare(0,prefix.size(),prefix)==0){
25  std::string relativeKey = key.substr(prefix.length()+1);
26  int endSubTable = -1;//TODO implement sub table listening better
27  for(unsigned int i = 0; i<relativeKey.length(); ++i){
28  if(relativeKey.at(i)==NetworkTable::PATH_SEPARATOR_CHAR){//is sub table
29  endSubTable = i;
30  break;
31  }
32  }
33  if(endSubTable!=-1){
34  std::string subTableKey = relativeKey.substr(0, endSubTable);
35  if(notifiedTables.find(subTableKey)==notifiedTables.end()){
36  notifiedTables.insert(subTableKey);
37  EntryValue eValue;
38  eValue.ptr = targetSource->GetSubTable(subTableKey);
39  targetListener->ValueChanged(targetSource, subTableKey, eValue, true);
40  }
41  }
42  }
43  }
NetworkTable * GetSubTable(std::string key)
void ValueChanged(ITable *source, const std::string &key, EntryValue value, bool isNew)
Definition: ITable.h:26
virtual void ValueChanged(ITable *source, const std::string &key, EntryValue value, bool isNew)=0
NetworkTableSubListenerAdapter(std::string &prefix, NetworkTable *targetSource, ITableListener *targetListener)
Definition: ITable.h:13

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