⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shared_list.h

📁 Implementation of genetic algorithm, to search for desired extreme n-variable function.
💻 H
字号:
//---------------------------------------------------------------------------
#ifndef shared_listH
#define shared_listH

//---------------------------------------------------------------------------
#include <vector>
#include <boost/shared_ptr.hpp>

//---------------------------------------------------------------------------
template <typename T>
class TSharedList
{
  private:
	typedef std::vector<boost::shared_ptr<T> > list_type;
     typedef list_type::iterator iterator_type;

	boost::shared_ptr<list_type> list;
	iterator_type iter;

	T* temp;

	boost::shared_ptr<T> create(T* el)
	{
		boost::shared_ptr<T> p(el);
		return p;
	}

  public:
	TSharedList(void) : list(new list_type()) {}
	~TSharedList(void) {}

	unsigned add(T* el)
	{
		list->push_back(create(el));
		return list->size() - 1;
	}

	T const* item(unsigned index) const
	{
		unsigned count = list->size();
		if(index < 0 || index >= count)
			return 0;

		return list->at(index).get();
	}

	T* item(unsigned index)
	{
		unsigned count = list->size();
		if(index < 0 || index >= count)
			return temp;

		return list->at(index).get();
	}

	bool erase(unsigned index)
	{
		unsigned count = list->size();
		if(index < 0 || index >= count)
			return false;

		iter = list->begin();
		list->erase(iter + index);
		return true;
	}

	unsigned count(void) const
	{
		return list->size();
	}

	void clear(void)
	{
		list->clear();
	}

	TSharedList& operator=(TSharedList& L)
	{
		L.clear();
		for(int i = 0; i < list->count; i++)
			L.add(list->item(i));
		return L;
     }
};
//---------------------------------------------------------------------------
#endif /* plik 'shared_list.h' */


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -