/////////////////////////////////////////////////////////////////////
// Client.cpp - Client uses Element class without binding to //
// ver 2.0 its implemention, via the IElement interface //
// //
// Language: Visual Studio.Net, using standard C++ //
// Platform: Dell Dimension 8100, Windows 2000, SP 2 //
// Application: Demonstration of Programming to Interface for //
// CSE687, Spring 2003 //
// Author: Jim Fawcett, CST 2-187, Syracuse University //
// (315) 443-3948, jfawcett@twcny.rr.com //
/////////////////////////////////////////////////////////////////////
/*
Module Operation:
=================
Client provides a simple test of the The Element static library.
The library creates simple tagged, attributed elements with string
bodies, similar to that used with XML and HTML. The product is of
the form:
some text
The Client accesses the Element functionality through the IElement
interface, and creates an instance of the Element class, using the
interface static function CreateElement. Therefore, the client
has no compilation dependencies on the Element module. If we
change Element's implementation the client does not have to be
recompiled, only relinked to the new static library.
*/
///////////////////////////////////////////////////////////////////////
// Build Process //
///////////////////////////////////////////////////////////////////////
// Required Files: //
// IElement.h, client.cpp, element.lib, stdafx.h, stdafx.cpp //
// //
// Build Process: //
// cl /EHsc client.cpp element.lib //
// //
///////////////////////////////////////////////////////////////////////
/*
Maintenance History:
====================
- ver 2.0 : 01/24/06
- converted to use Element class from static library, via
the IElement interface.
- ver 1.0 : 01/20/03
- first release
*/
//
#include "stdafx.h"
#include
#include "IElement.h" // note: does not include Element.h
using namespace std;
//----< display title with ==== underline >--------------------------
void Title(const std::string &s)
{
string underline(s.length(),'=');
std::cout << "\n " << s.c_str();
std::cout << "\n " << underline;
}
//----< display title with ---- underline >--------------------------
void SubTitle(const std::string &s)
{
string underline(s.length(),'-');
std::cout << "\n\n " << s.c_str();
std::cout << "\n " << underline;
}
int _tmain(int argc, _TCHAR* argv[])
{
Title("Testing IElement class");
SubTitle("creating elements through interface");
IElement& e1 = *IElement::CreateElement("first");
e1.addAttribute("title","first element");
e1.addAttribute("status","new");
e1.addBody("This is some boring text");
SubTitle("Element e1");
cout << "\n " << e1.makeElement();
IElement& e2 = *IElement::CreateElement("second");
e2.addBody("second dose of text");
SubTitle("Element e2");
cout << "\n " << e2.makeElement();
IElement& root = * IElement::CreateElement("root");
root.addBody(e1.makeElement() + e2.makeElement());
SubTitle("Element root with e1 joined to e2 for body");
cout << "\n " << root.makeElement();
delete &e1;
delete &e2;
delete &root;
cout << "\n\n";
return 0;
}