Click here to Skip to main content
15,893,722 members
Articles / Programming Languages / C++

Composites-Visitors pattern: the OOP way

Rate me:
Please Sign up or sign in to vote.
4.37/5 (9 votes)
15 Aug 2004CPOL13 min read 50.4K   387   28  
An implementation of the composite-visitors pattern avoiding the use of rescursive generic code.
// CompVisit.cpp 
//

#include "stdafx.h"
#include "LTypes/RefCnt.h"
#include "shapes.h"

using namespace GE_;


int _tmain(int argc, _TCHAR* argv[])
{
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	STRACE(trc, 1, ("Begin test\n"))

	//create a drawing
	NApp::CGroup::Ptr pDrawing;
	pDrawing.New();
	
	//add in it teo circles
	new NApp::CCircle(pDrawing, NApp::SRect(10,10,60,60));
	new NApp::CCircle(pDrawing, NApp::SRect(80,10,140,60), 0, 7);
	
	//create a subgroup
	NApp::CGroup* pSubDraw = new NApp::CGroup;
	pSubDraw->SetParent(pDrawing); //palce it into the drawing
	pSubDraw->SetAttribute(NApp::CGroup::attr_linecolor, 4);

	//add two rectangles in the subgroup
	new NApp::CRectangle(pSubDraw, NApp::SRect(20,70,130,120));
	new NApp::CRectangle(pSubDraw, NApp::SRect(20,125,130,150), 5);

	NApp::CDrawer::Ptr pDrw; pDrw.New();
	pDrawing->Draw(pDrw);

	std::cout << "\nPress any key ...\n";
	while(!getch());
	trc("End Program\n");
	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Italy Italy
Born and living in Milan (Italy), I'm an engineer in electronics actually working in the ICT department of an important oil/gas & energy company as responsible for planning and engineering of ICT infrastructures.
Interested in programming since the '70s, today I still define architectures for the ICT, deploying dedicated specific client application for engineering purposes, working with C++, MFC, STL, and recently also C# and D.

Comments and Discussions