Initial commit
This commit is contained in:
Executable
+216
@@ -0,0 +1,216 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <wfr/common/types/LwdTypes.h>
|
||||
#include <wfr/common/wfs/ActivityInstance.h>
|
||||
#include <wfr/common/wfs/instances/LoopActivityInstance.h>
|
||||
|
||||
namespace wfr {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy port values.
|
||||
*
|
||||
* Generic case
|
||||
**/
|
||||
|
||||
template<class C>
|
||||
inline bool portbuffer_copy(C& dest, const C& src) {
|
||||
if ( !dest.isReady() && src.isReady() ) {
|
||||
dest = src;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<class C>
|
||||
inline bool portbuffer_copy(C& dest, const lwd::_lwd_member_type<C>& src) {
|
||||
if ( !dest.isReady() && src.getValue().isReady() ) {
|
||||
dest = src.getValue();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy port values.
|
||||
*
|
||||
* Specialised cases for loop ports.
|
||||
**/
|
||||
|
||||
template<class C>
|
||||
inline bool portbuffer_copy(lwd::_lwd_loop_port<C>& dest, const C& src, const wfr_size_t& nextIter) {
|
||||
if ( src.isReady() && dest.getNextIterationID() < nextIter ) {
|
||||
dest.setValue(src.getValue());
|
||||
dest.setNextIterationID(nextIter);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<class C>
|
||||
inline bool portbuffer_copy(C& dest, const lwd::_lwd_loop_port<C>& src, const wfr_id_t& iterationID) {
|
||||
if ( !dest.isReady() && src.getNextIterationID()-1 == iterationID ) {
|
||||
dest.setValue(src.getValue());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy port values.
|
||||
*
|
||||
* Specialised cases for collections.
|
||||
**/
|
||||
|
||||
template<class C>
|
||||
inline bool portbuffer_copy(lwd::iwir_collection<C, 1>& dest, const C& src, const wfr_id_t& index) {
|
||||
if (dest.getSize() <= index || !dest.getEntry(index).isReady()) {
|
||||
dest.setEntryValue(index, src);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<class C>
|
||||
inline bool portbuffer_copy(lwd::iwir_collection<C, 1>& dest, const lwd::_lwd_member_type<C>& src, const wfr_id_t& index) {
|
||||
if ((dest.getSize() <= index || !dest.getEntry(index).isReady()) && src.isReady() ) {
|
||||
dest.setEntryValue(index, src.getValue());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<class C, wfr_size_t N>
|
||||
inline bool portbuffer_copy(lwd::iwir_collection<C, N>& dest, const lwd::iwir_collection<C, N-1>& src, const wfr_id_t& index) {
|
||||
if (dest.getSize() <= index || !dest.getEntry(index).isReady()) {
|
||||
dest.setEntryValue(index, src);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<class C, wfr_size_t N>
|
||||
inline bool portbuffer_copy(lwd::iwir_collection<C, N>& dest, const lwd::_lwd_member_type<lwd::iwir_collection<C, N-1>>& src, const wfr_id_t& index) {
|
||||
if ((dest.getSize() <= index || !dest.getEntry(index).isReady()) && src.isReady() ) {
|
||||
dest.setEntryValue(index, src.getValue());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<class C, wfr_size_t N, wfr_size_t F>
|
||||
struct collection_flatten {
|
||||
inline wfr_size_t operator()(lwd::iwir_collection<C, N>& dest, const lwd::iwir_collection<C, N+F-1>& src, const wfr_id_t& index) {
|
||||
wfr_size_t retval = 0;
|
||||
for (wfr_size_t i = 0; i < src.getSize(); i++) {
|
||||
retval += collection_flatten<C, N, F-1>()(dest, src.getEntryValue(i), index + retval);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
};
|
||||
|
||||
template<class C, wfr_size_t N>
|
||||
struct collection_flatten<C, N, 1> {
|
||||
inline wfr_size_t operator()(lwd::iwir_collection<C, N>& dest, const lwd::iwir_collection<C, N>& src, const wfr_id_t& index) {
|
||||
for (wfr_size_t i = 0; i < src.getSize(); i++) {
|
||||
if (dest.getSize() <= index+i || !dest.getEntryStatus(index + i)) {
|
||||
dest.setEntryValue(index + i, src.getEntryValue(i));
|
||||
}
|
||||
}
|
||||
return src.getSize();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<wfr_size_t F, class C, wfr_size_t N>
|
||||
inline wfr_size_t portbuffer_copy_flatten(lwd::iwir_collection<C, N>& dest, const lwd::iwir_collection<C, N+F-1>& src, const wfr_id_t& index = 0) {
|
||||
if (!dest.isReady() && src.isReady()) {
|
||||
return collection_flatten<C, N, F>()(dest, src, index);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the predecessor with the given index has finished execution.
|
||||
**/
|
||||
inline bool wfr_pred_isfinished(const wfs::ActivityInstance& instance, const wfr_id_t& predIndex) {
|
||||
auto predname = instance.getPredecessors()[predIndex];
|
||||
if (predname != nullptr) {
|
||||
return predname->getInstanceStatus() == wfr::wfs::ActivityInstanceStatus::Finished;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the predecessor with the given index is ready-for-execution.
|
||||
**/
|
||||
inline bool wfr_pred_isReady(const wfr::wfs::ActivityInstance& instance, const wfr_id_t& predIndex) {
|
||||
auto predname = instance.getPredecessors()[predIndex];
|
||||
if (predname != nullptr) {
|
||||
return predname->getInstanceStatus() == wfr::wfs::ActivityInstanceStatus::ReadyForExecution;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the previous loop iteration has finished execution.
|
||||
**/
|
||||
inline bool wfr_previter_isfinished(const wfr::wfs::ActivityInstance& loopinstance, const wfr_id_t& currentIterID) {
|
||||
if (currentIterID == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return loopinstance.as<wfr::wfs::LoopActivityInstance>().hasIterationFinished(currentIterID -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the parent activity is ready-for-execution.
|
||||
**/
|
||||
inline bool wfr_parent_isReady(const wfr::wfs::ActivityInstance& instance) {
|
||||
auto predname = instance.getParentActivity();
|
||||
if (predname != nullptr) {
|
||||
return predname->getInstanceStatus() == wfr::wfs::ActivityInstanceStatus::ReadyForExecution;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the parent activity has finished execution.
|
||||
**/
|
||||
inline bool wfr_parent_isfinished(const wfr::wfs::ActivityInstance& instance) {
|
||||
auto predname = instance.getParentActivity();
|
||||
if (predname != nullptr) {
|
||||
return predname->getInstanceStatus() == wfr::wfs::ActivityInstanceStatus::Finished;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // end namespace wfr
|
||||
Reference in New Issue
Block a user