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 Story, a class encapsulating a collection of PlotLines. Each
16 : // PlotLine is an ordered sequence of events that will be played independently
17 : // (ie. on their own threads), with potential interactions between them via
18 : // the Backdrop and any causality constraints, themselves represented via
19 : // LinkedEvents.
20 : //
21 : // The serialized file is organized as follows:
22 : //
23 : // - PlotLines
24 : // - number of plot lines
25 : // - PlotLine0
26 : // - number of events in plot line
27 : // - Event0
28 : // - type of event 0
29 : // - serialization of event 0
30 : // - ... repeat for other events ...
31 : // - ... repeated for other plot lines ...
32 : // - causality constraints (the number of linked events is implicit)
33 : // - (linked event id) of event with input constraints
34 : // - number of input constraints
35 : // - (linked event id) of input constraint 0
36 : // - ... repeated for other constraints ...
37 :
38 : #ifndef SYZYGY_BARD_STORY_H_
39 : #define SYZYGY_BARD_STORY_H_
40 :
41 : #include "base/memory/scoped_vector.h"
42 : #include "syzygy/bard/event.h"
43 : #include "syzygy/core/serialization.h"
44 :
45 : namespace bard {
46 :
47 : // Container class for storing and serializing PlotLines.
48 : class Story {
49 : public:
50 : // A PlotLine is a simple ordered sequence of events. At some point we may
51 : // need additional functionality on this class but for now a vector does the
52 : // job.
53 : using PlotLine = ScopedVector<EventInterface>;
54 :
55 E : Story() {}
56 :
57 : // Add a PlotLine to the Story. Story takes ownership of all the PlotLines
58 : // that it stores.
59 : // @param event a scoped_ptr to the PlotLine to be added to the Story.
60 : // @returns a pointer to the stored PlotLine.
61 : PlotLine* AddPlotLine(scoped_ptr<PlotLine> plot_line);
62 :
63 : // Creates a plotline, adding it to this story.
64 : // @returns a pointer to the created plotline.
65 : PlotLine* CreatePlotLine();
66 :
67 : // @name Serialization methods.
68 : // @{
69 : bool Save(core::OutArchive* out_archive) const;
70 : bool Load(core::InArchive* in_archive);
71 : // @}
72 :
73 : // Accessor for unittesting.
74 E : const ScopedVector<PlotLine>& plot_lines() const { return plot_lines_; }
75 :
76 : private:
77 : ScopedVector<PlotLine> plot_lines_;
78 :
79 : DISALLOW_COPY_AND_ASSIGN(Story);
80 : };
81 :
82 : } // namespace bard
83 :
84 : #endif // SYZYGY_BARD_STORY_H_
|