DetectorGraph  2.0
graphstatestore.cpp
Go to the documentation of this file.
1 // Copyright 2017 Nest Labs, Inc.
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 #include "graphstatestore.hpp"
16 
17 namespace DetectorGraph
18 {
19 
21 {
22  ptr::shared_ptr<const StateSnapshot> tZeroState = ptr::shared_ptr<const StateSnapshot>(new StateSnapshot());
23  mStatesLookbackQueue.push(tZeroState);
24 }
25 
27 {
28 }
29 
30 void GraphStateStore::TakeNewSnapshot(const std::list< ptr::shared_ptr<const TopicState> >& arTopicStates)
31 {
32  // do it
33  ptr::shared_ptr<const StateSnapshot> newState;
34 
35  // mStatesLookbackQueue is ensured to not be empty by the constructor.
36  newState = ptr::shared_ptr<const StateSnapshot>(new StateSnapshot(*(mStatesLookbackQueue.back()), arTopicStates));
37 
38  mStatesLookbackQueue.push(newState);
39 
40  const size_t MaxLookBack = 2;
41  if (mStatesLookbackQueue.size() > MaxLookBack)
42  {
43  mStatesLookbackQueue.pop();
44  }
45 }
46 
47 ptr::shared_ptr<const StateSnapshot> GraphStateStore::GetLastState() const
48 {
49  // mStatesLookbackQueue is ensured to not be empty by the constructor.
50  return mStatesLookbackQueue.back();
51 }
52 
53 }
The collection of TopicStates that represents the graph state so far.
ptr::shared_ptr< const StateSnapshot > GetLastState() const
Returns a safe shared pointer to the latest complete StateSnapshot.
~GraphStateStore()
Default Destructor.
GraphStateStore()
Constructs an empty graph store.
void TakeNewSnapshot(const std::list< ptr::shared_ptr< const TopicState > > &arTopicStates)
Takes a new state snapshot and appends it to the look back queue.