#pragma once #include #include #include namespace wfr { /** * Copy port values. * * Generic case **/ template inline bool portbuffer_copy(C& dest, const C& src) { if ( !dest.isReady() && src.isReady() ) { dest = src; return true; } else { return false; } } template inline bool portbuffer_copy(C& dest, const lwd::_lwd_member_type& src) { if ( !dest.isReady() && src.getValue().isReady() ) { dest = src.getValue(); return true; } else { return false; } } /** * Copy port values. * * Specialised cases for loop ports. **/ template inline bool portbuffer_copy(lwd::_lwd_loop_port& 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 inline bool portbuffer_copy(C& dest, const lwd::_lwd_loop_port& 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 inline bool portbuffer_copy(lwd::iwir_collection& 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 inline bool portbuffer_copy(lwd::iwir_collection& dest, const lwd::_lwd_member_type& 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 inline bool portbuffer_copy(lwd::iwir_collection& dest, const lwd::iwir_collection& src, const wfr_id_t& index) { if (dest.getSize() <= index || !dest.getEntry(index).isReady()) { dest.setEntryValue(index, src); return true; } else { return false; } } template inline bool portbuffer_copy(lwd::iwir_collection& dest, const lwd::_lwd_member_type>& 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 struct collection_flatten { inline wfr_size_t operator()(lwd::iwir_collection& dest, const lwd::iwir_collection& src, const wfr_id_t& index) { wfr_size_t retval = 0; for (wfr_size_t i = 0; i < src.getSize(); i++) { retval += collection_flatten()(dest, src.getEntryValue(i), index + retval); } return retval; } }; template struct collection_flatten { inline wfr_size_t operator()(lwd::iwir_collection& dest, const lwd::iwir_collection& 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 inline wfr_size_t portbuffer_copy_flatten(lwd::iwir_collection& dest, const lwd::iwir_collection& src, const wfr_id_t& index = 0) { if (!dest.isReady() && src.isReady()) { return collection_flatten()(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().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