Coverage for /Syzygy/bard/event.h

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
100.0%110.C++source

Line-by-line coverage:

   1    :  // Copyright 2015 Google Inc. All Rights Reserved.
   2    :  //
   3    :  // Licensed under the Apache License, Version 2.0 (the "License");
   4    :  // you may not use this file except in compliance with the License.
   5    :  // You may obtain a copy of the License at
   6    :  //
   7    :  //     http://www.apache.org/licenses/LICENSE-2.0
   8    :  //
   9    :  // Unless required by applicable law or agreed to in writing, software
  10    :  // distributed under the License is distributed on an "AS IS" BASIS,
  11    :  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12    :  // See the License for the specific language governing permissions and
  13    :  // limitations under the License.
  14    :  //
  15    :  // Declares an interface for recording events, which can be played by a
  16    :  // story teller in an arbitrary order, and during which stats can be
  17    :  // collected for user analysis.
  18    :  #ifndef SYZYGY_BARD_EVENT_H_
  19    :  #define SYZYGY_BARD_EVENT_H_
  20    :  
  21    :  #include <memory>
  22    :  
  23    :  #include "syzygy/core/serialization.h"
  24    :  
  25    :  namespace bard {
  26    :  
  27    :  // Interface for storing and playing events.
  28    :  class EventInterface {
  29    :   public:
  30    :    // Enum of all non-abstract classes that extend the EventInterface.
  31    :    // New events should only be added at the end of the Enum (but before
  32    :    // kMaxEventType), to maintain backwards compatibility for
  33    :    // serialization/deserialization.
  34    :    enum EventType {
  35    :      kLinkedEvent = 0,
  36    :      // Memory-profiling related events.
  37    :      kHeapAllocEvent = 1,
  38    :      kHeapCreateEvent = 2,
  39    :      kHeapDestroyEvent = 3,
  40    :      kHeapFreeEvent = 4,
  41    :      kHeapReAllocEvent = 5,
  42    :      kHeapSetInformationEvent = 6,
  43    :      kHeapSizeEvent = 7,
  44    :      // New events must be added strictly to the end in order for serialization
  45    :      // to maintain backwards compatibility.
  46    :      // This must come last.
  47    :      kMaxEventType
  48    :    };
  49    :  
  50  E :    virtual ~EventInterface() { }
  51    :  
  52    :    // This event's EventType.
  53    :    // @returns the EventType enum representing this event.
  54    :    virtual EventType type() const = 0;
  55    :  
  56    :    // Plays the recorded function call, possibly modifying the current
  57    :    // backdrop.
  58    :    // @note The backdrop is a piece of user data, specific to a set of
  59    :    // events, whose exact type is dictated by convention.
  60    :    // @param backdrop the backdrop.
  61    :    // @returns true if Play succeeds without any problems, false otherwise.
  62    :    virtual bool Play(void* backdrop) = 0;
  63    :  
  64    :    // Equality comparator.
  65    :    virtual bool Equals(const EventInterface* rhs) const = 0;
  66    :  
  67    :    // NOTE: Every non-abstract class that extends Event should
  68    :    // also implement the following functions:
  69    :    //
  70    :    // Serialize an Event in an OutArchive.
  71    :    // @param event a ponter to the event to be serialized.
  72    :    // @param out_archive where to serialize the event.
  73    :    // @returns true on success, false otherwise.
  74    :    // static bool Save(const EventInterface* const event,
  75    :    //                  core::OutArchive* out_archive);
  76    :    //
  77    :    // Deserialize an event from an InArchive.
  78    :    // @param in_archive from where to deserialize this event.
  79    :    // @returns a scoped__ptr to the newly created event on success,
  80    :    //     an nullptr std::unique_ptr otherwise.
  81    :    // static std::unique_ptr<DerivedEvent> Load(core::InArchive* in_archive);
  82    :    //
  83    :    // NOTE: A DerivedEvent event should NOT save its own type in the Save method.
  84    :    // That should be done by a root serialization, which will need to read the
  85    :    // type to call the appropriate static save method from the appropriate class.
  86    :  
  87    :    // Serialization of an event. These will automatically dispatch to the
  88    :    // appropriately typed serialization mechanism.
  89    :    static bool Save(const EventInterface* event, core::OutArchive* out_archive);
  90    :    static std::unique_ptr<EventInterface> Load(core::InArchive* in_archive);
  91    :  };
  92    :  
  93    :  }  // namespace bard
  94    :  
  95    :  #endif  // SYZYGY_BARD_EVENT_H_

Coverage information generated Fri Jul 29 11:00:21 2016.