source: cpp/gdk/multimap.h @ 34

Last change on this file since 34 was 5, checked in by sz, 16 years ago

added the GDK (Genotype Development Kit)

File size: 2.3 KB
RevLine 
[5]1// This file is a part of Framsticks GDK library.
2// Copyright (C) 2002-2006  Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.frams.alife.pl/ for further information.
4
5#ifndef _MULTIMAP_H_
6#define _MULTIMAP_H_
7
8#include "multirange.h"
9
10class SingleMapping
11{
12  public:
13SingleMapping(int b,const MultiRange& t):begin(b),to(t) {}
14SingleMapping(int b):begin(b) {}
15SingleMapping(const SingleMapping& sm):begin(sm.begin),to(sm.to) {}
16int begin;
17MultiRange to;
18};
19
20/** MultiMap - used for conversion mapping.
21    see @ref convmap
22  */
23class MultiMap
24{
25/** list of (SingleMapping*) */
26SList data;
27
28SingleMapping* getData(int i) const {return (SingleMapping*)data(i);}
29void addData(int i,SingleMapping* mapping) {data.insert(i,(void*)mapping);}
30void removeData(int i) {data.remove(i);}
31int findData(int x) const;
32int getBegin(int i) const {return getData(i)->begin;}
33
34// addRangeXXX return the shift for range numbers > r
35int addRange(int &r,const MultiRange& mr);
36// value of 'r' is adjusted according to its range number change
37int addRangeBeginEnd(int &r,int begin,int end,const MultiRange& mr);
38
39  public:
40MultiMap() {}
41MultiMap(const MultiMap& mm) {operator=(mm);}
42~MultiMap();
43void operator=(const MultiMap& mm);
44
45void clear();
46int isEmpty() const {return data.size()==0;}
47int mappingCount() const {return data.size();}
48SingleMapping* getMapping(int i) const {return (SingleMapping*)getData(i);}
49int findMappingId(int x) const {return findData(x);}
50int rangeCount() const {return isEmpty()?0:data.size()-1;}
51IRange getRange(int i) const;
52
53int getBegin() const;
54int getEnd() const;
55
56void add(const IRange& from,const IRange& to) {add(from.begin, from.end, MultiRange(to));}
57void add(const IRange& from,const MultiRange& to) {add(from.begin, from.end, to);}
58void add(int from1,int from2,int to1,int to2) {add(from1,from2,MultiRange(to1,to2));}
59void add(int from1,int from2,const MultiRange& to);
60void add(const MultiRange& from,const MultiRange& to);
61void add(const MultiMap& mm);
62void addCombined(const MultiMap& m1,const MultiMap& m2);
63void addReversed(const MultiMap& mm);
64
65const MultiRange& map(int x) const;
66MultiRange map(int begin,int end) const;
67MultiRange map(const IRange& range) const {return map(range.begin, range.end);}
68MultiRange map(const MultiRange& ranges) const;
69
70void print() const;
71void print2() const;
72};
73
74#endif
75
76
Note: See TracBrowser for help on using the repository browser.