// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma // de Barcelona (UAB). // // This work is licensed under the terms of the MIT license. // For a copy, see . #pragma once #include "carla/AtomicSharedPtr.h" #include namespace carla { namespace client { namespace detail { class Simulator; struct EpisodeProxyPointerType { using Shared = std::shared_ptr; using Strong = AtomicSharedPtr; using Weak = std::weak_ptr; }; /// Provides access to the Simulator during a given episode. After the episode /// is ended any access to the simulator throws an std::runtime_error. template class EpisodeProxyImpl { public: using SharedPtrType = EpisodeProxyPointerType::Shared; EpisodeProxyImpl() = default; EpisodeProxyImpl(SharedPtrType simulator); template EpisodeProxyImpl(EpisodeProxyImpl other) : _episode_id(other._episode_id), _simulator(other._simulator) {} auto GetId() const noexcept { return _episode_id; } SharedPtrType TryLock() const noexcept; /// Same as TryLock but never return nullptr. /// /// @throw std::runtime_error if episode is gone. SharedPtrType Lock() const; bool IsValid() const noexcept { return TryLock() != nullptr; } void Clear() noexcept; private: template friend class EpisodeProxyImpl; uint64_t _episode_id; PointerT _simulator; }; using EpisodeProxy = EpisodeProxyImpl; using WeakEpisodeProxy = EpisodeProxyImpl; } // namespace detail } // namespace client } // namespace carla