Click here to Skip to main content
15,894,097 members
Articles / Desktop Programming / WTL

Cyclomatic Complexity Viewer

Rate me:
Please Sign up or sign in to vote.
4.29/5 (13 votes)
30 Jun 20055 min read 108.7K   2.8K   34  
A Cyclomatic complexity viewer application.
/*  ====================================================================
*  Copyright (c) 2005 Franz Klein, franzaklein@yahoo.co.uk
*  All rights reserved.
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions
*  are met:
*
*  1. Redistributions of source code must retain the above copyright
*     notice, this list of conditions and the following disclaimer.
*
*  2. Redistributions in binary form must reproduce the above copyright
*     notice, this list of conditions and the following disclaimer in the
*     documentation and/or other materials provided with the distribution.
*
*  3. The name of the author may not be used to endorse or promote products
*     derived from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
*  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
*  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
*  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
*  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
*  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
*  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*  ====================================================================
*/

// GraphPreparator.cpp: Implementierung der Klasse CGraphPreparator.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "GraphPreparator.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Konstruktion/Destruktion
//////////////////////////////////////////////////////////////////////

CGraphPreparator::CGraphPreparator()
{
	graphdata = CSingleton<Data>::Instance();
	currentlocation = graphdata->begin();
}

CGraphPreparator::~CGraphPreparator()
{

}

bool CGraphPreparator::PrepareGraph(string& filename)
{
//	outputfile = filename;
	while (currentlocation != graphdata->end())
	{
		currentlocation++;
	}
	return false;
}

#ifdef _DEBUG
void CGraphPreparator::WriteVector(string filename)
{
	file.open(filename.c_str(), ios::out | ios::trunc);
	vector<Data>::iterator start = graphdata->begin();
	while (start != graphdata->end())
	{
		OutputTabs(start->level);
		file << "node number " << start->num << endl;
		OutputTabs(start->level);
		file << "label " << start->label << endl;
		OutputTabs(start->level);
		file << "level " << start->level << endl;
		OutputTabs(start->level);
		file << "word " << start->word << endl;
		OutputTabs(start->level);
		file << "inif " << start->inif << endl;
		OutputTabs(start->level);
		file << "inelse " << start->inelse << endl;
		OutputTabs(start->level);
		file << "inwhile " << start->inwhile << endl;
		OutputTabs(start->level);
		file << "indo " << start->indo << endl;
		OutputTabs(start->level);
		file << "incase " << start->incase << endl;
		OutputTabs(start->level);
		file << "casenum " << start->casenum << endl;
		OutputTabs(start->level);
		file << "children: " << endl;
		if (start->label != "}")
		{
			vector<Data*>::iterator child = start->children.begin();
			while (child != start->children.end())
			{
		OutputTabs(start->level);
				file << "child label " << (*child)->label << endl;
		OutputTabs(start->level);
				file << "child word " << (*child)->word << endl;
		OutputTabs(start->level);
				file << "child number " << (*child)->num << endl;
				child++;
			}
		}
		file << endl;
		start++;
	}
	file.close();
}

void CGraphPreparator::WriteNodes(string filename)
{
	file.open(filename.c_str(), ios::out | ios::trunc);
	vector<Data>::iterator start = graphdata->begin();
	while (start != graphdata->end())
	{
		file << start->level << " ";
//		OutputTabs(start->level);
		file << start->label << endl;
		file << "inelse " << start->inelse << endl;
		file << "iselse " << start->iselse << endl;
		file << "inif " << start->inif << endl;
		file << "indo " << start->indo << endl;
		if (start->label != "}")
		{
			vector<Data*>::iterator child = start->children.begin();
			while (child != start->children.end())
			{
				OutputTabs(start->level);
				file << "child label " << (*child)->label << endl;
				child++;
			}
		}
		file << endl;
		start++;
	}
	file.close();
}

void CGraphPreparator::OutputTabs(int level)
{
	file << level;
	for (int i = 0; i < level; i++)
		file << "\t";
}
#endif		//_DEBUG

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United Kingdom United Kingdom
I am a qualified Veterinary Surgeon who prefers treating computers with viruses than animals with viruses. I have recently completed a MEng German Informatics degree at the University of Reading with a 2:1. I also have the ISEB Foundation Certificate in Software Testing.

Currently I am umemployed and desparately looking for a job in the IT industry.

Comments and Discussions