Clipboard.hpp 4.69 KB
 Simon Spannagel committed Apr 16, 2018 1 2 3 /** * @file * @brief Store objects for exachange between modules on the clipboard  Simon Spannagel committed Apr 16, 2018 4  * @copyright Copyright (c) 2017 CERN and the Corryvreckan authors.  Simon Spannagel committed Apr 16, 2018 5 6 7 8 9 10 11  * This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md". * In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an * Intergovernmental Organization or submit itself to any jurisdiction. */ #ifndef CORRYVRECKAN_CLIPBOARD_H #define CORRYVRECKAN_CLIPBOARD_H  Daniel Hynds committed Sep 17, 2015 12   Simon Spannagel committed Oct 09, 2017 13 #include  Simon Spannagel committed Feb 21, 2019 14 #include  Daniel Hynds committed Sep 17, 2015 15 #include  Simon Spannagel committed Nov 14, 2018 16 #include  Simon Spannagel committed Jul 04, 2018 17 #include  Daniel Hynds committed Sep 17, 2015 18   Simon Spannagel committed Apr 16, 2018 19 #include "core/utils/log.h"  Simon Spannagel committed Feb 21, 2019 20 #include "objects/Event.hpp"  Simon Spannagel committed Apr 16, 2018 21 #include "objects/Object.hpp"  Daniel Hynds committed Sep 17, 2015 22   Simon Spannagel committed Mar 05, 2018 23 namespace corryvreckan {  Simon Spannagel committed May 21, 2019 24  typedef std::map>> ClipboardData;  Daniel Hynds committed Oct 20, 2017 25   Simon Spannagel committed Apr 16, 2018 26 27 28 29 30 31 32 33 34 35  /** * @brief Class for temporary data storage for exachange between modules * * The Clipboard class is used to transfer information between modules during the event processing. \ref Objects can be * placed on the clipboard, and retrieved by their name. At the end of each event, the clipboard is * wiped clean. * * In addition, a permanent clipboard storage area for variables of type double is provided, which allow to exchange * information which should outlast a single event. This is dubbed the "persistent storage" */  Simon Spannagel committed Mar 05, 2018 36  class Clipboard {  Simon Spannagel committed Sep 10, 2019 37  friend class ModuleManager;  Simon Spannagel committed Oct 06, 2017 38   Simon Spannagel committed Mar 05, 2018 39  public:  Simon Spannagel committed Apr 16, 2018 40 41 42  /** * @brief Construct the clipboard */  Simon Spannagel committed Mar 05, 2018 43  Clipboard() {}  Simon Spannagel committed Apr 16, 2018 44 45 46  /** * @brief Required virtual destructor */  Simon Spannagel committed Mar 05, 2018 47  virtual ~Clipboard() {}  Simon Spannagel committed Oct 06, 2017 48   Simon Spannagel committed Apr 16, 2018 49  /**  Simon Spannagel committed Sep 05, 2019 50 51 52  * @brief Method to add a vector of objects to the clipboard * @param objects Shared pointer to vector of objects to be stored * @param key Identifying key for this set of objects. Defaults to empty key  Simon Spannagel committed Apr 16, 2018 53  */  Simon Spannagel committed Sep 10, 2019 54  template void putData(std::shared_ptr> objects, const std::string& key = "");  Simon Spannagel committed Oct 06, 2017 55   Simon Spannagel committed Apr 16, 2018 56  /**  Simon Spannagel committed Sep 05, 2019 57 58  * @brief Method to retrieve objects from the clipboard * @param key Identifying key of objects to be fetched. Defaults to empty key  Simon Spannagel committed Apr 16, 2018 59  */  Simon Spannagel committed Sep 10, 2019 60  template std::shared_ptr> getData(const std::string& key = "") const;  Simon Spannagel committed Oct 06, 2017 61   Simon Spannagel committed Feb 21, 2019 62 63 64 65  /** * @brief Check whether an event has been defined * @return true if an event has been defined, false otherwise */  Simon Spannagel committed Sep 10, 2019 66  bool isEventDefined() const;  Simon Spannagel committed Feb 21, 2019 67 68 69 70 71 72  /** * @brief Store the event object * @param event The event object to be stored * @thorws InvalidDataError in case an event exist already */  Simon Spannagel committed Sep 10, 2019 73  void putEvent(std::shared_ptr event);  Simon Spannagel committed Feb 21, 2019 74 75 76 77 78 79  /** * @brief Retrieve the event object * @returnShared pointer to the event * @throws MissingDataError in case no event is available. */  Simon Spannagel committed Sep 10, 2019 80  std::shared_ptr getEvent() const;  Simon Spannagel committed Feb 21, 2019 81   Simon Spannagel committed Apr 16, 2018 82 83 84 85 86  /** * @brief Store or update variable on the persistent clipboard storage * @param name Name of the variable * @param value Value to be stored */  Simon Spannagel committed Sep 10, 2019 87  void putPersistentData(std::string name, double value);  Simon Spannagel committed Apr 16, 2018 88 89 90 91 92  /** * @brief Retrieve variable from the persistent clipboard storage * @param name Name of the variable * @return Stored value from the persistent clipboard storage  Simon Spannagel committed Feb 21, 2019 93  * @throws MissingDataError in case the key is not found.  Simon Spannagel committed Apr 16, 2018 94  */  Simon Spannagel committed Sep 10, 2019 95  double getPersistentData(std::string name) const;  Simon Spannagel committed Oct 12, 2017 96   Simon Spannagel committed Jul 04, 2018 97 98 99 100 101  /** * @brief Check if variable exists on the persistent clipboard storage * @param name Name of the variable * @return True if value exists, false if it does not exist. */  Simon Spannagel committed Sep 10, 2019 102  bool hasPersistentData(std::string name) const;  Simon Spannagel committed Jul 04, 2018 103   Simon Spannagel committed Apr 16, 2018 104 105 106 107  /** * @brief Get a list of currently held collections on the clipboard event storage * @return Vector of collections names currently stored on the clipboard */  Simon Spannagel committed Sep 10, 2019 108  std::vector listCollections() const;  Simon Spannagel committed Oct 06, 2017 109   Simon Spannagel committed May 21, 2019 110 111 112 113  /** * @brief Retrieve all currently stored clipboard data * @return All clipboard data */  Simon Spannagel committed Sep 10, 2019 114  const ClipboardData& getAll() const;  Simon Spannagel committed Apr 16, 2018 115   Simon Spannagel committed May 21, 2019 116  private:  Simon Spannagel committed Sep 10, 2019 117 118 119 120 121  /** * @brief Clear the event storage of the clipboard */ void clear();  Simon Spannagel committed Nov 06, 2018 122 123  // Container for data, list of all data held ClipboardData m_data;  Simon Spannagel committed Apr 16, 2018 124 125  // Persistent clipboard storage  Simon Spannagel committed Jul 04, 2018 126  std::unordered_map m_persistent_data;  Simon Spannagel committed Feb 21, 2019 127 128 129  // Store the current time slice: std::shared_ptr m_event{};  Simon Spannagel committed Mar 05, 2018 130 131  }; } // namespace corryvreckan  Daniel Hynds committed Sep 17, 2015 132   Simon Spannagel committed Nov 14, 2018 133 134 135 // Include template members #include "Clipboard.tpp"  Simon Spannagel committed Apr 16, 2018 136 #endif // CORRYVRECKAN_CLIPBOARD_H