Clipboard.hpp 3.78 KB
Newer Older
1
2
3
/**
 * @file
 * @brief Store objects for exachange between modules on the clipboard
4
 * @copyright Copyright (c) 2017 CERN and the Corryvreckan authors.
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
12

Simon Spannagel's avatar
Simon Spannagel committed
13
#include <iostream>
14
#include <string>
Simon Spannagel's avatar
Simon Spannagel committed
15
#include <unordered_map>
16

17
#include "core/utils/log.h"
18
#include "objects/Object.hpp"
19

20
namespace corryvreckan {
21

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"
     */
32
    class Clipboard {
Simon Spannagel's avatar
Simon Spannagel committed
33

34
    public:
35
36
37
        /**
         * @brief Construct the clipboard
         */
38
        Clipboard() {}
39
40
41
        /**
         * @brief Required virtual destructor
         */
42
        virtual ~Clipboard() {}
Simon Spannagel's avatar
Simon Spannagel committed
43

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
         */
49
        void put(std::string name, Objects* objects);
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
         */
57
        void put(std::string name, std::string type, Objects* objects);
Simon Spannagel's avatar
Simon Spannagel committed
58

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's avatar
Simon Spannagel committed
66

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
78
         * @throws MissingKeyError in case the key is not found.
79
         */
80
        double get_persistent(std::string name);
81

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);

89
90
91
        /**
         * @brief Clear the event storage of the clipboard
         */
92
        void clear();
Simon Spannagel's avatar
Simon Spannagel committed
93

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<std::string> listCollections();
Simon Spannagel's avatar
Simon Spannagel committed
99

100
    private:
101
        typedef std::map<std::string, Objects*> ClipboardData;
102

103
104
        // Container for data, list of all data held
        ClipboardData m_data;
105
106

        // Persistent clipboard storage
Simon Spannagel's avatar
Simon Spannagel committed
107
        std::unordered_map<std::string, double> m_persistent_data;
108
109
    };
} // namespace corryvreckan
110

111
#endif // CORRYVRECKAN_CLIPBOARD_H