-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeriv.h
77 lines (71 loc) · 2.03 KB
/
Deriv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* @file: Deriv.h
* Files Deriv.* contain an example of how one could expand class Graph,
* deriving a new class from it.
* In this file we'll create class EGraph, representing extended graph. Instead
* of ordinary nodes (class Node) and edges (class Edge) it will be consisted
* of nodes and edges with additional fields: ENode and EEdge.
*
* This file contains declarations.
*/
#ifndef DERIV_H
#define DERIV_H
#include "Graph/predecls.h"
#include <QtGui/QGraphicsTextItem>
#include <QtGui/QtGui>
#include <QtGui/QApplication>
#include <QtCore/QLineF>
class EGraph;
class ENode;
class EEdge;
typedef EGraph* pEGraph;
typedef ENode* pENode;
typedef EEdge* pEEdge;
/// Example of a class derived from Node
/**
* This class contains two new variables: x,y.
* Note that such class might be derived not only from class Node.
* In this example, it's derived from Node and QGraphicsTextItem.
*/
class ENode: public Node, QGraphicsTextItem {
public:
int x,y; //< New fields
ENode(pEGraph pg): Node((pGraph)pg){
x = y = 0;
}
virtual void Dump();
friend class EEdge;
friend class EGraph;
};
/// Example of a class derived from Edge
/**
* This class contains one new variable: w.
*/
class EEdge: public Edge {
public:
int w; //< New field
EEdge(pENode from, pENode to): Edge((pNode)from, (pNode)to){
w = 0;
}
virtual void Dump();
friend class EGraph;
friend class ENode;
};
/// Example of a class derived from Graph
/**
* We need to reimplement functions for creating and deleting new nodes/edges,
* because we ought to use new types (ENode instead of Node and EEdge instead
* of Edge).
*/
class EGraph: public Graph {
public:
virtual pENode AddNode();
virtual pEEdge AddEdge(pNode from, pNode to);
virtual void FreeNode(pNode p);
virtual void FreeEdge(pEdge p);
friend class EEdge;
friend class ENode;
};
/// This function illustrates how to use class EGraph.
void Derivation_Example();
#endif