WPILib 2012
WPILibRoboticsLibraryforFRC
NetworkTables/Key.h
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 #ifndef __KEY_H__
00008 #define __KEY_H__
00009 
00010 #include "NetworkTables/Data.h"
00011 #include "NetworkTables/InterfaceConstants.h"
00012 
00013 #include <map>
00014 #include <string>
00015 
00016 class NetworkTable;
00017 
00018 namespace NetworkTables
00019 {
00020 
00021 class Entry;
00022 
00023 class Key : public Data
00024 {
00025         friend class Connection;
00026         friend class Entry;
00027         friend class KeyConnectionListener;
00028         friend class NetworkTable;
00029 public:
00030         Key(NetworkTable *table, const char *keyName);
00031         virtual ~Key();
00032         NetworkTable *GetTable() {return m_table;}
00033         NetworkTables_Types GetType();
00034         Entry *GetEntry() {return m_entry.get();}
00035         std::string GetName() {return m_name;}
00036         UINT32 GetId() {return m_id;}
00037         void Encode(Buffer *buffer);
00038 
00039         static Key *GetKey(UINT32 id);
00040 
00041 private:
00042         std::auto_ptr<Entry> SetEntry(std::auto_ptr<Entry> entry);
00043         bool HasEntry() {return m_entry.get() != NULL;}
00044         void EncodeName(Buffer *buffer);
00045 
00046         static UINT32 AllocateId();
00047 
00048         NetworkTable *m_table;
00049         std::string m_name;
00050         // Keys are responsible for entrys' memory
00051         std::auto_ptr<Entry> m_entry;
00052         UINT32 m_id;
00053 
00054         static SEM_ID _staticLock;
00055         static std::map<UINT32, Key *> _idsMap;
00056         static UINT32 _currentId;
00057 };
00058 
00059 } // namespace
00060 
00061 #endif
00062 
 All Classes Functions Variables