90 lines
1.8 KiB
C++
90 lines
1.8 KiB
C++
//#
|
|
|
|
//# main.c
|
|
|
|
//#
|
|
|
|
//# =======================================================
|
|
|
|
//# Lab i Avacerad C++
|
|
|
|
//# 4. Figures
|
|
|
|
//#
|
|
|
|
//#
|
|
|
|
//# Christian Ohlsson
|
|
|
|
//# Daniel Alfredsson
|
|
|
|
//# Karlstads universitet
|
|
|
|
//# 991013
|
|
|
|
//# =======================================================
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream.h>
|
|
|
|
#include "Graphics.h"
|
|
|
|
#include "line.h"
|
|
|
|
#include "rectngle.h"
|
|
|
|
#include "circle.h"
|
|
|
|
#include "flist.h"
|
|
|
|
#include "CmplxFgr.h"
|
|
|
|
#include "pstream.h"
|
|
|
|
#include "pcircle.h"
|
|
|
|
#include "prctngle.h"
|
|
|
|
|
|
|
|
void archive(int& i, PStream& ps){
|
|
|
|
if(ps.isSaving())
|
|
|
|
ps<<i<<endl;
|
|
|
|
else
|
|
|
|
ps>>i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void archive(Point& i, PStream& ps){
|
|
|
|
if(ps.isSaving()){
|
|
|
|
ps<<i.getx()<<endl;
|
|
|
|
ps<<i.gety()<<endl;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
int x;
|
|
|
|
ps>>x;
|
|
|
|
i.setx(x);
|
|
|
|
ps>>x;
|
|
|
|
i.sety(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void main(void) {
|
|
|
|
Graphics g;
|
|
|
|
Persistent *pFig1, *pFig2, *newFig1, *newFig2, *newFig3, *newFig4;
|
|
|
|
PStream ps;
|
|
|
|
|
|
|
|
Pcircle pc(1,2,3,4);
|
|
|
|
Prectangle pr(5,6,7,8,9);
|
|
|
|
|
|
|
|
pFig1 = &pc;
|
|
|
|
pFig2 = ≺
|
|
|
|
|
|
|
|
// Save to file
|
|
|
|
ps.save("test.dat");
|
|
|
|
ps.archive(pFig1);
|
|
|
|
ps.archive(pFig1);
|
|
|
|
ps.archive(pFig2);
|
|
|
|
ps.archive(pFig1);
|
|
|
|
ps.close();
|
|
|
|
|
|
|
|
// Restore from file
|
|
|
|
ps.load("test.dat");
|
|
|
|
ps.archive(newFig1);
|
|
|
|
ps.archive(newFig2);
|
|
|
|
ps.archive(newFig3);
|
|
|
|
ps.archive(newFig4); // Does not exist on file...
|
|
|
|
ps.close();
|
|
|
|
|
|
|
|
// Draw the figure objects..
|
|
|
|
PersFig* psf = (PersFig*)newFig1;
|
|
|
|
psf->draw(g);
|
|
|
|
psf = (PersFig*)≺
|
|
|
|
psf->draw(g);
|
|
|
|
|
|
|
|
// This is just to show the pointers...
|
|
|
|
cout << "\nFigurePtr1: " << (int)newFig1 << endl;
|
|
|
|
cout << "FigurePtr2: " << (int)newFig2 << endl;
|
|
|
|
cout << "FigurePtr3: " << (int)newFig3 << endl;
|
|
|
|
cout << "FigurePtr4: " << (int)newFig4 << endl;
|
|
|
|
|
|
|
|
char x;
|
|
|
|
cin >> x;
|
|
|
|
}
|
|
|