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

📄 shapecomposite.cpp

📁 financal instrument pricing using c
💻 CPP
字号:
// ShapeComposite.hpp
//
// Simple shape composite class using the STL list class.
// The composite stores shape pointers. It does it's own memory management.
//
// 15 september 1998	RD	Started
//
// (C) Datasim Education BV

#include "ShapeComposite.hpp"


ShapeComposite::ShapeComposite(): Shape()
{ // Default constructor

	sl=std::list<Shape*>();
}


ShapeComposite::~ShapeComposite()
{ // Destructor

	RemoveAll();
}

// Iterator functions
ShapeComposite::iterator ShapeComposite::Begin()
{ // Return iterator at begin of composite

	return sl.begin();
}

ShapeComposite::const_iterator ShapeComposite::Begin() const
{ // Return const iterator at begin of composite

	return sl.begin();
}

ShapeComposite::iterator ShapeComposite::End()
{ // Return iterator after end of composite

	return sl.end();
}

ShapeComposite::const_iterator ShapeComposite::End() const
{ // Return const iterator after end of composite

	return sl.end();
}

// Selectors
int ShapeComposite::Count() const
{ // Return the number of shapes in the composite

	return sl.size();
}

// Add functions
void ShapeComposite::AddFront(Shape* s)
{ // Add shape at the beginning of shapelist. No copy is made.

	sl.push_front(s);
}

void ShapeComposite::AddBack(Shape* s)
{ // Add shape at the end of shapelist. No copy is made.

	sl.push_back(s);
}

// Remove functions
void ShapeComposite::RemoveLast()
{ // Remove last shape

	delete sl.back();		// Delete the shape
	sl.pop_back();			// Remove shape pointer from list
}

void ShapeComposite::RemoveFirst()
{ // Remove first shape

	delete sl.front();		// Delete the shape
	sl.pop_front();			// Remove shape pointer from list
}

void ShapeComposite::RemoveAll()
{ // Remove all shapes from the list

	// Create STL list iterator
	std::list<Shape*>::iterator it;

	for (it=sl.begin(); it!=sl.end(); it++)
	{ // Delete every shape in the list

		delete (*it);	// Delete shape
	}

	// Remove the shape pointers from the list
	sl.clear();
}

// Operators

⌨️ 快捷键说明

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