Click here to Skip to main content
15,885,980 members
Articles / Containers / Virtual Machine

An extendable report editor

Rate me:
Please Sign up or sign in to vote.
5.00/5 (11 votes)
3 Sep 2008CPOL3 min read 41K   2K   35  
An extendable report editor. You can simply add your own controls without recompiling the program or writing annoying plug-ins.
// HeaderFile.cpp: implementation of the CHeaderFile class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "HeaderFile.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
char *CHeaderFile::str_end_of_xml = "[This is the end of XML!]\r\n";
int CHeaderFile::max_header_size = 128 * 1024;

CHeaderFile::CHeaderFile()
{
    this->InitBasic();
}
CHeaderFile::~CHeaderFile()
{
    this->Destroy();
}
int CHeaderFile::InitBasic()
{
    return OK;
}
int CHeaderFile::Init()
{
    this->InitBasic();	
    return OK;
}
int  CHeaderFile::Destroy()
{
    this->InitBasic();
    return OK;
}

int CHeaderFile::WriteToFile(CFileBase *file_des, CFileBase *file_src, CXml *pxml)
{
	//pxml can be NULL, if so only file_src is written to the file_des
	ASSERT(file_des);
	ASSERT(file_src);

	if(pxml)
	{
		pxml->WriteToFile(file_des);
		file_des->Puts(CHeaderFile::str_end_of_xml);
	}
	file_des->WriteFile(file_src);
	
	return OK;
}

int CHeaderFile::WriteToFile(char *fn_des, CFileBase *file_src, CXml *pxml)
{
	CFile file;
	int ret;
	
	ASSERT(file_src);
	ASSERT(pxml);
	
	file.Init();
	ret = file.OpenFile(fn_des,"wb+");
	ASSERT(ret);

	CHeaderFile::WriteToFile(&file,file_src,pxml);

	file.Destroy();

	return OK;
}

//return value is the header size;
int CHeaderFile::LoadHeader(CFileBase *header_file, CXml *pxml)
{
	CMem mem;
	int pos,hsize = -1;
	
	ASSERT(header_file);
	ASSERT(pxml);

	mem.Init();
	mem.Malloc(CHeaderFile::max_header_size + 10);

	header_file->Seek(0);
	header_file->WriteToFile(&mem,CHeaderFile::max_header_size);

	mem.Seek(0);
	pos = mem.SearchStr(CHeaderFile::str_end_of_xml,0,0);

	if(pos >= 0)
	{
		hsize = pos + strlen(CHeaderFile::str_end_of_xml);
	}

	mem.SetChar(pos,0);
	mem.SetSize(pos);

	pxml->LoadXml(&mem);

	mem.Destroy();

	return hsize;
}

int CHeaderFile::LoadHeader(char *fn, CXml *pxml)
{
	int pos;

	ASSERT(pxml);

	CFile file;

	file.Init();
	file.OpenFile(fn,"rb");

	pos = CHeaderFile::LoadHeader(&file,pxml);

	file.Destroy();

	return pos;
}

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
Software Developer
China China
26 years old, 2 years work experience.

Comments and Discussions