Now you can download a copy of these docs so you can use them offline! Download now
Key.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 "NetworkTables/Key.h" 00008 00009 #include "NetworkTables/Buffer.h" 00010 #include "NetworkTables/Entry.h" 00011 #include "NetworkTables/NetworkTable.h" 00012 #include "Synchronized.h" 00013 00014 namespace NetworkTables 00015 { 00016 00017 SEM_ID Key::_staticLock = semMCreate(SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);; 00018 std::map<UINT32, Key *> Key::_idsMap; 00019 UINT32 Key::_currentId = 0; 00020 00021 Key::Key(NetworkTable *table, const char *keyName) : 00022 m_table(table), 00023 m_name(keyName), 00024 m_entry(NULL), 00025 m_id(AllocateId()) 00026 { 00027 _idsMap.insert(std::pair<UINT32, Key *>(m_id, this)); 00028 } 00029 00030 Key::~Key() 00031 { 00032 _idsMap.erase(m_id); 00033 } 00034 00035 NetworkTables_Types Key::GetType() 00036 { 00037 if (m_entry.get() == NULL) 00038 return kNetworkTables_Types_NONE; 00039 return m_entry->GetType(); 00040 } 00041 00042 void Key::Encode(Buffer *buffer) 00043 { 00044 buffer->WriteByte(kNetworkTables_ASSIGNMENT); 00045 m_table->EncodeName(buffer); 00046 buffer->WriteString(m_name); 00047 buffer->WriteId(m_id); 00048 } 00049 00050 std::auto_ptr<Entry> Key::SetEntry(std::auto_ptr<Entry> entry) 00051 { 00052 Entry *old = m_entry.release(); 00053 m_entry = entry; 00054 m_entry->SetKey(this); 00055 return std::auto_ptr<Entry>(old); 00056 } 00057 00058 Key *Key::GetKey(UINT32 id) 00059 { 00060 return _idsMap[id]; 00061 } 00062 00063 void Key::EncodeName(Buffer *buffer) 00064 { 00065 buffer->WriteId(m_id); 00066 } 00067 00068 UINT32 Key::AllocateId() 00069 { 00070 Synchronized sync(_staticLock); 00071 return ++_currentId; 00072 } 00073 00074 } // namespace
Generated on Thu Jan 12 2012 22:35:20 for WPILibC++ by
1.7.1