LCOV - code coverage report
Current view: top level - xenolith/application - XLEventHeader.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 2 100.0 %
Date: 2024-05-12 00:16:13 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2020 Roman Katuntsev <sbkarr@stappler.org>
       3             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       4             : 
       5             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       6             :  of this software and associated documentation files (the "Software"), to deal
       7             :  in the Software without restriction, including without limitation the rights
       8             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       9             :  copies of the Software, and to permit persons to whom the Software is
      10             :  furnished to do so, subject to the following conditions:
      11             : 
      12             :  The above copyright notice and this permission notice shall be included in
      13             :  all copies or substantial portions of the Software.
      14             : 
      15             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      16             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      17             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      18             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      19             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      20             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      21             :  THE SOFTWARE.
      22             :  **/
      23             : 
      24             : #ifndef XENOLITH_APPLICATION_XLEVENTHEADER_H_
      25             : #define XENOLITH_APPLICATION_XLEVENTHEADER_H_
      26             : 
      27             : #include "XLCommon.h"
      28             : #include "SPData.h"
      29             : 
      30             : #define XL_DECLARE_EVENT_CLASS(class, event) \
      31             :         STAPPLER_VERSIONIZED_NAMESPACE::xenolith::EventHeader class::event(#class, #class "." #event);
      32             : 
      33             : #define XL_DECLARE_EVENT(class, catName, event) \
      34             :         STAPPLER_VERSIONIZED_NAMESPACE::xenolith::EventHeader class::event(catName, catName "." #event);
      35             : 
      36             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      37             : 
      38             : class Event;
      39             : 
      40             : /* Event headers contains category and id of event.
      41             :  Headers should be used to statically declare event to be recognized by dispatcher and listeners
      42             :  Header declares unique event name, to be used, when we need to recognize this event
      43             : 
      44             :  EventHeaders should be declared statically with simple constructor:
      45             :         EventHeader eventHeader(Category);
      46             :  */
      47             : 
      48             : class EventHeader {
      49             : public:
      50             :         using Category = int;
      51             :         using EventID = int;
      52             : 
      53             :         static Category getCategoryForName(StringView catName);
      54             : public:
      55             : 
      56             :         EventHeader() = delete;
      57             :         EventHeader(StringView catName, StringView eventName);
      58             :         EventHeader(Category cat, StringView eventName);
      59             :         ~EventHeader();
      60             : 
      61             :         EventHeader(const EventHeader &other);
      62             :         EventHeader(EventHeader &&other);
      63             : 
      64             :         EventHeader &operator=(const EventHeader &other);
      65             :         EventHeader &operator=(EventHeader &&other);
      66             : 
      67             :         Category getCategory() const;
      68             :         EventID getEventID() const;
      69             :         StringView getName() const;
      70             : 
      71             :         bool isInCategory(Category cat) const;
      72             : 
      73             :         operator int ();
      74             : 
      75             :         bool operator == (const Event &event) const;
      76             : 
      77             :         template <typename T>
      78        1597 :         inline void operator() (Ref *object, const T &value) const { send(object, value); }
      79             : 
      80           8 :         inline void operator() (Ref *object) const { send(object); }
      81             : 
      82             : protected:
      83             :         void send(Ref *object, int64_t value) const;
      84             :         void send(Ref *object, double value) const;
      85             :         void send(Ref *object, bool value) const;
      86             :         void send(Ref *object, Ref *value) const;
      87             :         void send(Ref *object, const char *value) const;
      88             :         void send(Ref *object, const String &value) const;
      89             :         void send(Ref *object, const StringView &value) const;
      90             :         void send(Ref *object, const Value &value) const;
      91             :         void send(Ref *object = nullptr) const;
      92             : 
      93             :         Category _category = 0;
      94             :         EventID _id = 0;
      95             :         StringView _name;
      96             : };
      97             : 
      98             : }
      99             : 
     100             : #endif /* XENOLITH_APPLICATION_XLEVENTHEADER_H_ */

Generated by: LCOV version 1.14