File: resource.h

package info (click to toggle)
atom4 4.1-6
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 656 kB
  • ctags: 947
  • sloc: cpp: 4,461; makefile: 54; sh: 21; perl: 6
file content (68 lines) | stat: -rw-r--r-- 1,180 bytes parent folder | download | duplicates (6)
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
/*
 * Simple resource management base classes
 * Header file
 *
 * $Id$
 */

#ifndef RESOURCE_H
#define RESOURCE_H

#include <exception.h>


/* EXCEPTIONS */

class resource_exception : public exception {
public:
  resource_exception(char *msg) : exception(msg) {}
  resource_exception(char *fmt, int i) : exception(fmt, i) {}
};


/* CLASSES */

// TODO:
// - resource dependencies
class resource {
  int ref;				// reference counter
protected:
  virtual void load()=0;
  virtual void unload()=0;
public:
  resource();
  virtual ~resource();

  // Dynamic loading stuff
  int is_loaded() { return ref>0; }
  void alloc();
  void dealloc();
};

template <class res_t>
class eresource : public resource {
  res_t res;
protected:
  virtual void load() {}
  virtual void unload() {}
public:
  eresource(res_t r) : res(r) {}
  ~eresource() {}

  operator res_t () { return res; }
};

class resourceman {
  int num_static_ids;
  resource **staticres;			// static resources [O[O]]
public:
  resourceman(int num_static_ids);
  ~resourceman();

  void init_resource(int id, resource *r);	// [O]
  resource *allocate(int id);		// [R]()
  void deallocate(int id);
};


#endif // RESOURCE_H