16 #ifndef TORC_GENERIC_VECTOR_HPP
17 #define TORC_GENERIC_VECTOR_HPP
24 #ifdef GENOM_SERIALIZATION
25 #include <boost/bind.hpp>
26 #include <boost/mem_fn.hpp>
27 #include <boost/serialization/access.hpp>
28 #include <boost/serialization/base_object.hpp>
29 #include <boost/serialization/vector.hpp>
30 #include <boost/serialization/shared_ptr.hpp>
31 #include <boost/serialization/split_member.hpp>
32 #endif //GENOM_SERIALIZATION
49 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve = false>
51 #ifdef GENOM_SERIALIZATION
52 friend class boost::serialization::access;
53 #endif //GENOM_SERIALIZATION
98 virtual void addChild(
const boost::shared_ptr<Type>& inChild,
99 const std::vector<int>& inIndices)
throw(
Error);
153 virtual const Pointer get(
const std::vector<SizeType>& inIndices)
const throw (
Error);
209 const std::vector<
SizeType>& inLimits) throw (Error);
212 inline
void autoBlast() const throw (Error);
215 const std::vector<
SizeType>& limits) const;
267 #ifdef GENOM_SERIALIZATION
268 template <
class Archive>
void load(Archive& ar,
unsigned int);
270 template <
class Archive>
void save(Archive& ar,
unsigned int)
const;
272 BOOST_SERIALIZATION_SPLIT_MEMBER()
273 #endif //GENOM_SERIALIZATION
288 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
291 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
Vector<
293 mChildren(), mFactory(), mIsPreserved(cPreserve), mPreservationThreshold(1024) {}
300 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
310 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
312 _ChildType, _ChildFactoryType, cPreserve>::getSize()
const {
313 return storageSize();
328 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
void
330 const boost::shared_ptr<Type>& inChild,
const std::vector<SizeType>& inIndices)
throw(Error) {
333 if(inIndices.size() > mLimits.size()) {
336 if(cPreserve && mChildren.empty()) {
340 e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__ );
361 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
const
362 typename Vector<_Type, _ChildType, _ChildFactoryType, cPreserve>::Pointer
364 inIndices)
const throw (Error) {
365 if(inIndices.size() != mLimits.size()) {
371 typename std::vector<SizeType>::const_iterator lend = mLimits.end();
372 typename std::vector<SizeType>::const_iterator limit = mLimits.begin();
373 typename std::vector<SizeType>::const_iterator index = inIndices.begin();
374 for(; limit != lend; ++limit, ++index) {
375 if(*index >= *limit) {
384 SizeType index = indicesToAbsoluteIndex(inIndices);
386 Pointer thisPtr = BaseType::getSharedThis();
387 boost::shared_ptr < ChildFactory > factory = getFactory();
395 if(cPreserve && mChildren.empty()) {
396 if(
false == mSparseElements.get(index, child)) {
399 factory->create(newChild);
400 newChild->setParentCollection(thisPtr);
401 newChild->setIndices(inIndices);
402 newChild->setAbsoluteIndex(index);
403 mSparseElements.set(index, newChild);
405 onChildCreate(newChild);
413 child = mChildren[index];
427 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
void
433 && mChildren.empty())
442 outChildren.insert(outChildren.end(), mChildren.begin(), mChildren.end());
446 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
450 std::for_each(mChildren.begin(), mChildren.end(), action);
463 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
void
465 inSource)
throw (Error) {
466 mChildren = inSource;
469 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
void
478 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
inline
481 if(!mFactory)
return;
482 if(mLimits.empty())
return;
501 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
inline
503 const boost::shared_ptr<ChildFactory>& inFactory,
const std::vector<SizeType>& inLimits)
505 if(inLimits.empty()) {
510 typename std::vector<SizeType>::const_iterator index = inLimits.begin();
511 typename std::vector<SizeType>::const_iterator lend = inLimits.end();
512 for(; index != lend; index++) {
521 setFactory(inFactory);
533 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
inline
536 mChildren.resize(mChildren.size() + size);
537 Pointer thisPtr = BaseType::getSharedThis();
538 std::vector < SizeType > indices(mLimits.size());
539 fill(indices.begin(), indices.end(), 0);
545 boost::shared_ptr < ChildFactory > factory = getFactory();
551 for(
SizeType index = 0; index < size; index++) {
553 bool createNew = (cPreserve && mSparseElements.getSize() > 0
554 && mSparseElements.get(index, child)) ?
false :
true;
558 factory->create(newChild);
559 newChild->setParentCollection(thisPtr);
560 newChild->setIndices(indices);
561 newChild->setAbsoluteIndex(index);
563 onChildCreate(newChild);
570 incrementIndices(indices, mLimits);
571 mChildren[index] = child;
573 mSparseElements.clear();
582 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
void
584 const throw (Error) {
585 if(cPreserve && mChildren.empty()) {
586 mSparseElements.getValues(outChildren);
587 }
else if(!mChildren.empty()) {
589 getChildren(outChildren);
598 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
void
600 const boost::shared_ptr<ChildType>& inCreatedChild)
const throw (Error) {
604 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
void
606 std::vector<SizeType>& indices,
const std::vector<SizeType>& limits)
const {
609 for(
SizeType i = 0; i < size; i++) {
612 if(indices[i] == limits[i]) {
622 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
inline
624 _ChildType, _ChildFactoryType, cPreserve>::indicesToAbsoluteIndex(
625 const std::vector<SizeType>& inIndices)
const {
628 for(
SizeType k = 1; k <= size; k++) {
630 for(
SizeType l = k + 1; l <= size; l++) {
631 prod *= mLimits[l - 1];
633 idx += prod * inIndices[k - 1];
638 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
inline
641 return std::accumulate(mLimits.begin(), mLimits.end(), 1,
642 std::multiplies<
typename Vector<_Type, _ChildType, _ChildFactoryType,
651 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
inline
653 std::vector<SizeType>& outLimits)
const {
654 outLimits.insert(outLimits.end(), mLimits.begin(), mLimits.end());
657 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
inline
667 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
void
669 const std::vector<SizeType>& inSource) {
678 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
inline
679 const boost::shared_ptr<_ChildFactoryType>
Vector<_Type, _ChildType, _ChildFactoryType,
680 cPreserve>::getFactory()
const {
689 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
691 const boost::shared_ptr<Vector::ChildFactory>& inSource) {
695 #ifdef GENOM_SERIALIZATION
696 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
698 Archive& ar,
unsigned int) {
699 ar & boost::serialization::base_object<BaseType>(*this);
702 ar & mSparseElements;
704 ar & mPreservationThreshold;
705 if(!mChildren.empty()) {
706 for_each(mChildren.begin(), mChildren.end(),
707 boost::bind(boost::mem_fn(&ChildType::setParentCollection), _1,
710 mSparseElements.applyOnAll(boost::bind(boost::mem_fn(&ChildType::setParentCollection), _1,
715 template <
typename _Type,
typename _ChildType,
typename _ChildFactoryType,
bool cPreserve>
716 template <
class Archive>
void Vector<_Type, _ChildType, _ChildFactoryType, cPreserve>::save(
717 Archive& ar,
unsigned int)
const {
718 ar & boost::serialization::base_object<BaseType>(*this);
721 ar & mSparseElements;
723 ar & mPreservationThreshold;
726 #endif //GENOM_SERIALIZATION
731 #endif // TORC_GENERIC_VECTOR_HPP
virtual void getCreatedChildren(List &outChildren) const
SizeType storageSize() const
SparseElements mSparseElements
std::vector< SizeType > mLimits
boost::shared_ptr< ChildType > ChildPointer
boost::shared_ptr< ChildFactory > mFactory
virtual void onChildCreate(const boost::shared_ptr< ChildType > &inCreatedChild) const
SizeType indicesToAbsoluteIndex(const std::vector< SizeType > &inIndices) const
Represents the usable instance of a port of a cell in another cell.
virtual void onAutoBlast() const
Interface for objects that can be composed within each other.
void incrementIndices(std::vector< SizeType > &indices, const std::vector< SizeType > &limits) const
virtual CompositionType getCompositionType() const
SizeType mPreservationThreshold
const boost::shared_ptr< ChildFactory > getFactory() const
Composite< _Type > BaseType
bool getIsPreserved() const
virtual void forceAutoBlast(void)
boost::shared_ptr< Type > Pointer
void setFactory(const boost::shared_ptr< ChildFactory > &inSource)
CompositionType
Defines possible Composition types.
BaseType::SizeType SizeType
_ChildFactoryType ChildFactory
The Error object thrown by different methods of EdifOM.
void constructChildren(const boost::shared_ptr< ChildFactory > &inFactory, const std::vector< SizeType > &inLimits)
void applyOnAllChildren(const _Action &action)
Contains definition for CompositionType.
void saveContextData(const std::string &inName, const boost::any &inSource)
Represents a reference to a bit of a port.
SymTab< SizeType, Pointer > SparseElements
virtual const Pointer get(const std::vector< SizeType > &inIndices) const
void setLimits(const std::vector< SizeType > &inSource)
boost::shared_ptr< _ChildFactoryType > ChildFactorySharedPtr
Pointer getSharedThis() const
virtual void getChildren(List &outChildren) const
void getLimits(std::vector< SizeType > &outLimits) const
virtual SizeType getSize() const
void setChildren(const List &inSource)
A placeholder for a factory method.
BaseType::Pointer Pointer
Vector< _Type, _ChildType, _ChildFactoryType, cPreserve > & operator=(const Vector< _Type, _ChildType, _ChildFactoryType, cPreserve > &source)
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
std::vector< Pointer > List