summaryrefslogtreecommitdiff
path: root/include/PCommon.h
blob: 63d73fac05ecf561db97aba84e0feef79227c76a (plain)
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
#ifndef __PCOMMON_H__
#define __PCOMMON_H__

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifndef _
#define _(x) x
#endif

#include <PTypes.h>
#include <limits.h>
#define P_INFINITY INT_MAX
#define M_INFINITY INT_MIN
void exception(int e, char *msg);

#ifdef __cplusplus
#include <iostream.h>

class PriorityList {
      protected:
	class GeneralException;
	int type;
	Key_t Key;
	Datas_t Datas;
	  PriorityList(Key_t IKey, Datas_t const &IDatas);

      public:
	  PriorityList(void);
	  virtual ~ PriorityList(void);

	virtual Key_t ReadKey(Cell C);
	virtual Datas_t ReadDatas(Cell C);
	virtual int n(void);
	virtual int rn(void) = 0;

	virtual void Dump(ostream & os) = 0;
	virtual bool IsEmpty(void) = 0;

	virtual Cell Min(void) = 0;
	virtual Cell Insert(Key_t IKey, Datas_t const &IDatas) = 0;
	virtual Key_t Extract_Min(Datas_t & Datas) = 0;
	virtual PriorityList *Union(PriorityList * P) = 0;
	virtual bool Lower_Key(Cell x, Key_t NKey) = 0;
	virtual Key_t Delete(Datas_t & Datas, Cell x) = 0;
	PriorityList *GenericUnion(PriorityList * P);
	int GetType(void);
};

#ifndef SWAP
template < class T > inline void SWAP(T & a, T & b)
{
	T tmp(a);

	a = b;
	b = tmp;
};
#endif

#else
#warning This librairy is only designed for a C++ compiler.
#ifndef SWAP
#define SWAP(a,b) {           \
  char T[sizeof(a)];          \
  memcpy(T, &a, sizeof(a));   \
  memcpy(&a, &b, sizeof(a));  \
  memcpy(&b, T, sizeof(a));   \
}
#endif
#endif

#ifdef DEBUG
extern int nc, nd;
#endif

#endif