WSF
WsfQuantumTask.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFQUANTUMTASK_HPP
13#define WSFQUANTUMTASK_HPP
14
15
16class UtScriptClass;
17class UtScriptTypes;
18
19#include "wsf_mil_export.h"
20
21#include <memory>
22
23#include "WsfTask.hpp"
24#include "WsfTaskResource.hpp"
25class WsfTrack;
26
27
29// class WsfQuantumTaskId
30//{
31// public:
32//
33// WsfQuantumTaskId(WsfStringId aTaskType,
34// WsfStringId aTargetName,
35// int aResourceType)
36// : mTaskType(aTaskType),
37// mTargetName(aTargetName),
38// mResourceType(aResourceType) {}
39//
40// bool operator==(const WsfQuantumTaskId& aRhs) const
41// {
42// return ((mTaskType == aRhs.mTaskType) &&
43// (mTargetName == aRhs.mTargetName) &&
44// (mResourceType == aRhs.mResourceType));
45// }
46//
47// bool operator!=(const WsfQuantumTaskId& aRhs) const
48// {
49// return (! operator==(aRhs));
50// }
51//
52// bool operator<(const WsfQuantumTaskId& aRhs) const
53// {
54// if (mTaskType < aRhs.mTaskType)
55// {
56// return true;
57// }
58// else if (mTaskType > aRhs.mTaskType)
59// {
60// return false;
61// }
62// else if (mTargetName < aRhs.mTargetName)
63// {
64// return true;
65// }
66// else if (mTargetName > aRhs.mTargetName)
67// {
68// return false;
69// }
70// return (mResourceType < aRhs.mResourceType);
71// }
72//
73// private:
74//
75// WsfStringId mTaskType;
76// WsfStringId mTargetName;
77// int mResourceType;
78// };
79
80
84class WSF_MIL_EXPORT WsfQuantumTask : public WsfTask
85{
86public:
87 WsfQuantumTask(double aPriority = 1.0,
88 const WsfTaskResource& aResource = std::move(WsfTaskResource()),
89 WsfTrack* aTrackPtr = nullptr);
90 WsfQuantumTask(const WsfQuantumTask& aSrc) = default;
92 ~WsfQuantumTask() override = default;
93 virtual WsfQuantumTask* Clone() const;
94
95 const char* GetScriptClassName() const override { return "WsfQuantumTask"; }
96 static std::unique_ptr<UtScriptClass> CreateScriptClass(const std::string& aClassName, UtScriptTypes* aScriptTypesPtr);
97
98 double GetPriority() { return mPriority; }
99 void SetPriority(double aVal) { mPriority = aVal; }
100
101 bool operator==(const WsfQuantumTask& aRhs) const
102 {
103 return (this->GetTargetName() == aRhs.GetTargetName() && this->GetResourceType() == aRhs.GetResourceType());
104 }
105
106 void SetUniqueId(unsigned int aUniqueId)
107 {
108 mUniqueId = aUniqueId;
109 mTaskId = mUniqueId;
110 }
111
112 // unsigned int UniqueId()
113 //{
114 // if (mUniqueId == 0)
115 // {
116 // mUniqueId = UniqueId(*(WsfTask*)this);
117 // mTaskId = mUniqueId;
118 // }
119 // return mUniqueId;
120 // }
121
122 unsigned int GetUniqueId() const
123 {
124 if (mUniqueId > 0)
125 {
126 return mUniqueId;
127 }
128 else
129 {
130 return GetUniqueId(*(WsfTask*)this);
131 }
132 }
133
134 static unsigned int GetUniqueId(WsfTask& aTask)
135 {
136 unsigned int id = 0;
137 // TODO: Rework this code. it depends on WsfStringId::UnsafeGetNumber, and assumes <=13 bit dictionary ID's
138 id |= ReverseBits((unsigned int)WsfStringId::UnsafeGetNumber(aTask.GetTaskType())); // pack "left" bits first
139 id |= (unsigned int)(WsfStringId::UnsafeGetNumber(aTask.GetTargetName()) *
140 8); // pack "right" bits, save for last 3 bits
141 id |= (unsigned int)aTask.GetResourceType(); // pack final 3 bits
142 return id;
143 }
144
145 operator unsigned int() const { return this->GetUniqueId(); }
146
147 // Taken from: http://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel
148 static unsigned int ReverseBits(unsigned int x)
149 {
150 x = ((x >> 1) & 0x55555555U) | ((x & 0x55555555U) << 1);
151 x = ((x >> 2) & 0x33333333U) | ((x & 0x33333333U) << 2);
152 x = ((x >> 4) & 0x0f0f0f0fU) | ((x & 0x0f0f0f0fU) << 4);
153 x = ((x >> 8) & 0x00ff00ffU) | ((x & 0x00ff00ffU) << 8);
154 x = ((x >> 16) & 0x0000ffffU) | ((x & 0x0000ffffU) << 16);
155 return x;
156 }
157
158private:
159 double mPriority;
160 unsigned int mUniqueId;
161 // WsfQuantumTaskId mId;
162};
163
164#endif
static unsigned int GetUniqueId(WsfTask &aTask)
Definition WsfQuantumTask.hpp:134
WsfQuantumTask(const WsfQuantumTask &aSrc)=default
bool operator==(const WsfQuantumTask &aRhs) const
Definition WsfQuantumTask.hpp:101
double GetPriority()
Definition WsfQuantumTask.hpp:98
static unsigned int ReverseBits(unsigned int x)
Definition WsfQuantumTask.hpp:148
const char * GetScriptClassName() const override
Definition WsfQuantumTask.hpp:95
~WsfQuantumTask() override=default
void SetPriority(double aVal)
Definition WsfQuantumTask.hpp:99
WsfQuantumTask(double aPriority=1.0, const WsfTaskResource &aResource=std::move(WsfTaskResource()), WsfTrack *aTrackPtr=nullptr)
Definition WsfQuantumTask.cpp:26
void SetUniqueId(unsigned int aUniqueId)
Definition WsfQuantumTask.hpp:106
WsfQuantumTask & operator=(const WsfQuantumTask &)=delete
virtual WsfQuantumTask * Clone() const
Definition WsfQuantumTask.cpp:41
unsigned int GetUniqueId() const
Definition WsfQuantumTask.hpp:122
unsigned int mTaskId
The serial number of the task.
Definition WsfTaskData.hpp:40
Attributes of a task-able resource.
Definition WsfTaskResource.hpp:30
WsfStringId GetTargetName() const
Definition WsfTask.hpp:76
int GetResourceType() const
Definition WsfTask.hpp:113
WsfStringId GetTaskType() const
Definition WsfTask.hpp:71
WsfTask()
Definition WsfTask.hpp:30
An object that represents an 'track' (perception) of something.
Definition WsfTrack.hpp:120
Copyrights Multiple, All Rights Reserved