Clipboard.hpp 3.78 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  Daniel Hynds committed Sep 17, 2015 14 #include  Simon Spannagel committed Jul 04, 2018 15 #include  Daniel Hynds committed Sep 17, 2015 16   Simon Spannagel committed Apr 16, 2018 17 #include "core/utils/log.h"  Simon Spannagel committed Apr 16, 2018 18 #include "objects/Object.hpp"  Daniel Hynds committed Sep 17, 2015 19   Simon Spannagel committed Mar 05, 2018 20 namespace corryvreckan {  Daniel Hynds committed Oct 20, 2017 21   Simon Spannagel committed Apr 16, 2018 22 23 24 25 26 27 28 29 30 31  /** * @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 32  class Clipboard {  Simon Spannagel committed Oct 06, 2017 33   Simon Spannagel committed Mar 05, 2018 34  public:  Simon Spannagel committed Apr 16, 2018 35 36 37  /** * @brief Construct the clipboard */  Simon Spannagel committed Mar 05, 2018 38  Clipboard() {}  Simon Spannagel committed Apr 16, 2018 39 40 41  /** * @brief Required virtual destructor */  Simon Spannagel committed Mar 05, 2018 42  virtual ~Clipboard() {}  Simon Spannagel committed Oct 06, 2017 43   Simon Spannagel committed Apr 16, 2018 44 45 46 47 48  /** * @brief Add object to the clipboard * @param name Name of the collection to be stored * @param objects vector of Objects to store */  Simon Spannagel committed Apr 16, 2018 49  void put(std::string name, Objects* objects);  Simon Spannagel committed Apr 16, 2018 50 51 52 53 54 55 56  /** * @brief Add object to the clipboard * @param name Name of the collection to be stored * @param type Type of the object collection to be stored * @param Objects vector of Objects to store */  Simon Spannagel committed Apr 16, 2018 57  void put(std::string name, std::string type, Objects* objects);  Simon Spannagel committed Oct 06, 2017 58   Simon Spannagel committed Apr 16, 2018 59 60 61 62 63 64 65  /** * @brief Retrieve objects from the clipboard * @param name Name of the object collection to fetch * @param type Type of objects to be retrieved * @return Vector of Object pointers */ Objects* get(std::string name, std::string type = "");  Simon Spannagel committed Oct 06, 2017 66   Simon Spannagel committed Apr 16, 2018 67 68 69 70 71 72 73 74 75 76 77  /** * @brief Store or update variable on the persistent clipboard storage * @param name Name of the variable * @param value Value to be stored */ void put_persistent(std::string name, double value); /** * @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 Jul 04, 2018 78  * @throws MissingKeyError in case the key is not found.  Simon Spannagel committed Apr 16, 2018 79  */  Simon Spannagel committed Apr 16, 2018 80  double get_persistent(std::string name);  Simon Spannagel committed Oct 12, 2017 81   Simon Spannagel committed Jul 04, 2018 82 83 84 85 86 87 88  /** * @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. */ bool has_persistent(std::string name);  Simon Spannagel committed Apr 16, 2018 89 90 91  /** * @brief Clear the event storage of the clipboard */  Simon Spannagel committed Apr 16, 2018 92  void clear();  Simon Spannagel committed Oct 06, 2017 93   Simon Spannagel committed Apr 16, 2018 94 95 96 97 98  /** * @brief Get a list of currently held collections on the clipboard event storage * @return Vector of collections names currently stored on the clipboard */ std::vector listCollections();  Simon Spannagel committed Oct 06, 2017 99   Simon Spannagel committed Mar 05, 2018 100  private:  Simon Spannagel committed Nov 06, 2018 101  typedef std::map ClipboardData;  Simon Spannagel committed Apr 16, 2018 102   Simon Spannagel committed Nov 06, 2018 103 104  // Container for data, list of all data held ClipboardData m_data;  Simon Spannagel committed Apr 16, 2018 105 106  // Persistent clipboard storage  Simon Spannagel committed Jul 04, 2018 107  std::unordered_map m_persistent_data;  Simon Spannagel committed Mar 05, 2018 108 109  }; } // namespace corryvreckan  Daniel Hynds committed Sep 17, 2015 110   Simon Spannagel committed Apr 16, 2018 111 #endif // CORRYVRECKAN_CLIPBOARD_H