Files
OpenSpace/include/openspace/mission/mission.h
Alexander Bock 820e90eab4 Happy new year
2025-01-14 16:21:08 +01:00

209 lines
7.9 KiB
C++

/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2025 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_CORE___MISSION___H__
#define __OPENSPACE_CORE___MISSION___H__
#include <openspace/util/timerange.h>
#include <openspace/util/time.h>
#include <optional>
#include <string>
#include <vector>
namespace ghoul { class Dictionary; }
namespace openspace {
namespace documentation { struct Documentation; }
struct Milestone {
std::string name;
Time date;
std::optional<std::string> description;
std::optional<std::string> image;
std::optional<std::string> link;
std::optional<std::vector<std::string>> actions;
};
/**
* Used to represent a named period of time within a mission. Allows nested phases, i.e.
* phases within phases. Designed for WORM usage (Write Once, Read Multiple), and,
* therefore, has only accessors.
*
* Each MissionPhase is characterized by its MissionPhase::name, a TimeRange, an optional
* MissionPhase::description, and optional subphases.
*/
class MissionPhase {
public:
/**
* Constructs a MissionPhase from the information provided in the \p dictionary. See
* the MissionPhase::Documentation for accepted ghoul::Dictionary values.
*
* \param dictionary The ghoul::Dictionary that contains information about the current
* MissionPhase
*
* \throw SpecificationError If the \p dictionary does not adhere to the Documentation
* \throw RuntimeError If the time range of subphases is smaller than the specified
* time range
* \throw RuntimeError If neither subphases or a time range is specified
*/
MissionPhase(const ghoul::Dictionary& dictionary);
/**
* Returns the name of the MissionPhase.
*
* \return The name of the MissionPhase
*/
const std::string& name() const;
/**
* Returns the TimeRange of the MissionPhase.
*
* \return The TimeRange of the MissionPhase
*/
const TimeRange& timeRange() const;
/**
* Returns the description of the MissionPhase.
*
* \return The description of the MissionPhase
*/
const std::string& description() const;
/**
* Returns the associated image of this MissionPhase. If no image is associated, this
* string will be empty.
*
* \return The associated image of the MissionPhase or the empty string
*/
const std::string& image() const;
/**
* Returns the associated link of this MissionPhase. If no link is associated, this
* string will be empty.
*
* \return The associated link of the MissionPhase or the empty string
*/
const std::string& link() const;
/**
* Returns all subphases sorted by start time.
*
* \return All subphases sorted by start time
*/
const std::vector<MissionPhase>& phases() const;
/**
* Returns all important dates.
*
* \return All important dates
*/
const std::vector<Milestone>& milestones() const;
/**
* Returns all actions.
*
* \return All actions
*/
const std::vector<std::string>& actions() const;
using Trace = std::vector<std::reference_wrapper<const MissionPhase>>;
/**
* Returns all MissionPhase%s whose MissionPhase::timeRange includes the provided
* \p time, up to a maximum subphase depth of \p maxDepth.
*
* \param time The time in which the subphases have to be active in order to be
* included
* \param maxDepth The maximum levels of subphases that will be considered. If this
* value is equal to `-1`, an infinite depth will be considered.
* \return A list of MissionPhases that cover the provided \p time
*/
Trace phaseTrace(double time, int maxDepth = -1) const;
/**
* Returns the Documentation that describes the ghoul::Dictionarty that this
* MissionPhase can be constructed from.
*
* \return The Documentation that describes the required structure for a Dictionary
*/
static documentation::Documentation Documentation();
protected:
/**
* Recursive function that walks the subphases and adds the MissionPhase%s that cover
* the provided \p time and adds these to the list of \p trace%s. Each recursive call
* will decrease the \p maxDepth counter until it reaches 0.
*
* \param time The time which the subphases have to cover to be added to the \p trace
* \param trace The list of MissionPhase%s that are active during the time \p time
* \param maxDepth The maximum depth of levels that will be considered
*
* \pre \p maxDepth must not be negative
*/
void phaseTrace(double time, Trace& trace, int maxDepth) const;
/// The name of the MissionPhase
std::string _name;
/// The description of the MissionPhase
std::string _description;
/// The range in time that is covered by this MissionPhase
TimeRange _timeRange;
/// A list of subphases into which this MissionPhase is separated
std::vector<MissionPhase> _subphases;
/// Image that is associated with this phase
std::string _image;
/// Link that is associated with this phase
std::string _link;
/// Actions associated with the phase
std::vector<std::string> _actions;
/// Important dates
std::vector<Milestone> _milestones;
};
/**
* A Mission is a list of MissionPhases that has a name, an optional description, a
* TimeRange for which the Mission is active, and a potential list of subphases.
*/
using Mission = MissionPhase;
/**
* This function constructs a Mission from the provided \p filename. The file must be a
* Lua table that describes the Mission according to MissionPhase::Documentation.
*
* \param filename The file that is used to create the Mission
* \return The constructed Mission
*
* \pre \p filename must not be empty
* \pre \p filename must not contain tokens
* \pre \p filename must exist
*/
Mission missionFromFile(const std::string& filename);
} // namespace openspace
#endif // __OPENSPACE_CORE___MISSION___H__