Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions model/gym-interface/cpp/container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,19 @@ OpenGymTupleContainer::Print(std::ostream& where) const
where << ")";
}

std::vector<std::string>
OpenGymDictContainer::GetKeys()
{
std::vector<std::string> keys;
for (std::map<std::string, Ptr<OpenGymDataContainer>>::iterator it = m_dict.begin();
it != m_dict.end();
++it)
{
keys.push_back(it->first);
}
return keys;
}

TypeId
OpenGymDictContainer::GetTypeId()
{
Expand Down
15 changes: 14 additions & 1 deletion model/gym-interface/cpp/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <ns3/object.h>
#include <ns3/type-name.h>
#include <cstdint>

namespace ns3
{
Expand Down Expand Up @@ -106,7 +107,7 @@ class OpenGymBoxContainer : public OpenGymDataContainer
container->Print(os);
return os;
}

void SetValue(uint32_t idx, T value);
bool AddValue(T value);
T GetValue(uint32_t idx);

Expand Down Expand Up @@ -243,6 +244,16 @@ OpenGymBoxContainer<T>::AddValue(T value)
return true;
}

template <typename T>
void
OpenGymBoxContainer<T>::SetValue(uint32_t idx, T value)
{
if (idx < m_data.size())
{
m_data[idx] = value;
}
}

template <typename T>
T
OpenGymBoxContainer<T>::GetValue(uint32_t idx)
Expand Down Expand Up @@ -336,6 +347,8 @@ class OpenGymDictContainer : public OpenGymDataContainer

void Print(std::ostream& where) const override;

std::vector<std::string> GetKeys();

friend std::ostream& operator<<(std::ostream& os, const Ptr<OpenGymDictContainer> container)
{
container->Print(os);
Expand Down