summaryrefslogtreecommitdiff
path: root/Simulator/include/simulation/Path.h
blob: d35d49fc7071146d9e42d5789758ee9ebf2cf278 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include "Section.h"
#include "modeling/ModelingTypes.h"

namespace Simulation
{
	/**
	 * \brief Holds all sections of the parent experiment, and returns the correct one
	 *		based on the current tick.
	 */
	class Path
	{
	public:
		explicit Path(int id) : id(id)
		{}


		/**
		 * \brief Adds the given section to this path. The begin tick of this section 
		 *		should not already be in use by one of the other sections in this path.
		 * \param section The section to add to this path.
		 */
		void addSection(DefaultSection section)
		{
			sections.push_back(section);
		}

		/**
		 * \brief Returns the section that is currently in use by taking the section
		 *		that has the greatest begin tick smaller than the current tick 
		 * \param currentTick The tick the simulator is simulating right now.
		 * \return The section that is currently in use.
		 */
		DefaultSection& getCurrentSection(uint32_t currentTick)
		{
			size_t currentSection = 0;

			uint32_t currentStartTick = 0;
			for(int i = 0; i < sections.size(); ++i)
			{
				uint32_t tempStartTick = sections.at(i).getStartTick();
				if(tempStartTick > currentStartTick && tempStartTick < currentTick)
					currentSection = i;
			}

			return sections.at(currentSection);
		}

	private:
		
		/**
		 * \brief The unordered vector of sections in this path. No pair of sections
		 *		should share the same begin tick. 
		 */
		std::vector<DefaultSection> sections;


		/**
		 * \brief The id of this path as it is in the database.
		 */
		int id;
	};
}