XJ music engine  1.9.6
In-game runtime engine for XJ music.
SegmentEntityStore.h
Go to the documentation of this file.
1 // Copyright (c) XJ Music Inc. (https://xjmusic.com) All Rights Reserved.
2 
3 #ifndef XJMUSIC_SEGMENT_ENTITY_STORE_H
4 #define XJMUSIC_SEGMENT_ENTITY_STORE_H
5 
6 #include <optional>
7 #include <set>
8 #include <string>
9 #include <vector>
10 
11 #include "Chain.h"
12 #include "Segment.h"
13 #include "SegmentChoice.h"
16 #include "SegmentChord.h"
17 #include "SegmentChordVoicing.h"
18 #include "SegmentMeme.h"
19 #include "SegmentMessage.h"
20 #include "SegmentMeta.h"
22 
23 using namespace XJ;
24 
25 #define SEGMENT_STORE_CORE_HEADERS(ENTITY, ENTITIES) \
26  const ENTITY *put(const ENTITY &choice); \
27  std::optional<const ENTITY *> read##ENTITY(int segmentId, const UUID &id); \
28  std::set<const ENTITY *> readAll##ENTITIES(int segmentId); \
29  std::set<const ENTITY *> readAll##ENTITIES(const std::set<int> &segmentIds); \
30  void delete##ENTITY(int segmentId, const UUID &id);
31 
32 
33 namespace XJ {
34 
44  std::optional<Chain> chain;
45  std::map<int, Segment> segments;
46  std::map<int, std::map<UUID, SegmentChoice>> segmentChoices;
47  std::map<int, std::map<UUID, SegmentChoiceArrangement>> segmentChoiceArrangements;
48  std::map<int, std::map<UUID, SegmentChoiceArrangementPick>> segmentChoiceArrangementPicks;
49  std::map<int, std::map<UUID, SegmentChord>> segmentChords;
50  std::map<int, std::map<UUID, SegmentChordVoicing>> segmentChordVoicings;
51  std::map<int, std::map<UUID, SegmentMeme>> segmentMemes;
52  std::map<int, std::map<UUID, SegmentMessage>> segmentMessages;
53  std::map<int, std::map<UUID, SegmentMeta>> segmentMetas;
54 
55  static void validate(SegmentMeme entity);
56 
57  static void validate(Segment entity);
58 
59  public:
61 
62  SEGMENT_STORE_CORE_HEADERS(SegmentChoiceArrangement, SegmentChoiceArrangements)
63 
64  SEGMENT_STORE_CORE_HEADERS(SegmentChoiceArrangementPick, SegmentChoiceArrangementPicks)
65 
67 
68  SEGMENT_STORE_CORE_HEADERS(SegmentChordVoicing, SegmentChordVoicings)
69 
71 
73 
75 
76  SegmentEntityStore() = default;
77 
82  Chain *put(const Chain &c);
83 
88  const Segment *put(const Segment &segment);
89 
94  std::optional<Chain *> readChain();
95 
100  std::optional<const Segment *> readSegment(int segmentId);
101 
111  std::optional<const Segment *> readSegmentAtChainMicros(const unsigned long long int chainMicros);
112 
119  std::vector<const Segment *> readAllSegments();
120 
128  std::vector<const Segment *> readAllSegmentsInState(Segment::State segmentState);
129 
137  std::vector<const Segment *> readSegmentsFromToOffset(int fromOffset, int toOffset);
138 
145  std::set<const SegmentEntity *> readAllSegmentEntities(const std::set<int> &segmentIds);
146 
154  std::vector<const Segment *> readAllSegmentsSpanning(const unsigned long long int fromChainMicros, const unsigned long long int toChainMicros);
155 
161  int readLastSegmentId() const;
162 
168  std::optional<const Segment *> readSegmentLast();
169 
177  std::optional<const SegmentChoice *> readChoice(int segmentId, Program::Type programType);
178 
185  std::string readChoiceHash(const Segment &segment);
186 
192  std::set<const SegmentChoiceArrangementPick *>
193  readAllSegmentChoiceArrangementPicks(const std::vector<const Segment *> &forSegments);
194 
201 
207  std::vector<const SegmentChord *> readOrderedSegmentChords(int segmentId);
208 
214  int getSegmentCount() const;
215 
221  bool empty() const;
222 
229  const Segment *updateSegment(Segment &segment);
230 
235  void deleteChain();
236 
241  void deleteSegment(int id);
242 
248  void deleteSegmentsBefore(int lastSegmentId);
249 
255  void deleteSegmentsAfter(int lastSegmentId);
256 
261  void clear();
262 
270  static void protectSegmentStateTransition(Segment::State fromState, Segment::State toState);
271 
279  static void onlyAllowSegmentStateTransitions(Segment::State toState, const std::set<Segment::State> &allowedStates);
280  };
281 
282 }// namespace XJ
283 
284 #endif//XJMUSIC_SEGMENT_ENTITY_STORE_H
Definition: Chain.h:14
Definition: Program.h:14
Definition: SegmentChoiceArrangementPick.h:14
Definition: SegmentChoiceArrangement.h:14
Definition: SegmentChoice.h:15
Definition: SegmentChordVoicing.h:16
Definition: SegmentChord.h:13
Definition: SegmentEntityStore.h:43
std::vector< const Segment * > readSegmentsFromToOffset(int fromOffset, int toOffset)
Definition: SegmentEntityStore.cpp:128
std::optional< const Segment * > readSegmentAtChainMicros(const unsigned long long int chainMicros)
Definition: SegmentEntityStore.cpp:84
static void protectSegmentStateTransition(Segment::State fromState, Segment::State toState)
Definition: SegmentEntityStore.cpp:323
const Segment * updateSegment(Segment &segment)
Definition: SegmentEntityStore.cpp:274
int readLastSegmentId() const
Definition: SegmentEntityStore.cpp:183
void deleteSegment(int id)
Definition: SegmentEntityStore.cpp:310
std::vector< const Segment * > readAllSegmentsSpanning(const unsigned long long int fromChainMicros, const unsigned long long int toChainMicros)
Definition: SegmentEntityStore.cpp:172
void clear()
Definition: SegmentEntityStore.cpp:411
std::string readChoiceHash(const Segment &segment)
Definition: SegmentEntityStore.cpp:213
std::optional< const Segment * > readSegment(int segmentId)
Definition: SegmentEntityStore.cpp:97
int getSegmentCount() const
Definition: SegmentEntityStore.cpp:264
std::optional< Chain * > readChain()
Definition: SegmentEntityStore.cpp:93
std::optional< const Segment * > readSegmentLast()
Definition: SegmentEntityStore.cpp:191
static void onlyAllowSegmentStateTransitions(Segment::State toState, const std::set< Segment::State > &allowedStates)
Definition: SegmentEntityStore.cpp:357
std::optional< const SegmentChoice * > readChoice(int segmentId, Program::Type programType)
Definition: SegmentEntityStore.cpp:200
Chain * put(const Chain &c)
Definition: SegmentEntityStore.cpp:74
std::vector< const Segment * > readAllSegmentsInState(Segment::State segmentState)
Definition: SegmentEntityStore.cpp:115
std::vector< const SegmentChord * > readOrderedSegmentChords(int segmentId)
Definition: SegmentEntityStore.cpp:253
void deleteSegmentsBefore(int lastSegmentId)
Definition: SegmentEntityStore.cpp:385
std::vector< const Segment * > readAllSegments()
Definition: SegmentEntityStore.cpp:102
std::set< const SegmentChoiceArrangementPick * > readAllSegmentChoiceArrangementPicks(const std::vector< const Segment * > &forSegments)
Definition: SegmentEntityStore.cpp:227
void deleteChain()
Definition: SegmentEntityStore.cpp:305
void deleteSegmentsAfter(int lastSegmentId)
Definition: SegmentEntityStore.cpp:398
std::set< const SegmentEntity * > readAllSegmentEntities(const std::set< int > &segmentIds)
Definition: SegmentEntityStore.cpp:139
bool empty() const
Definition: SegmentEntityStore.cpp:269
SEGMENT_STORE_CORE_HEADERS(SegmentMeta, SegmentMetas)
Definition: SegmentEntity.h:15
Definition: SegmentMeme.h:13
Definition: SegmentMessage.h:14
Definition: SegmentMeta.h:14
Definition: Segment.h:13
Definition: ActiveAudio.h:11