File: repclone.h

package info (click to toggle)
mixviews 1.20-10.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,928 kB
  • ctags: 5,960
  • sloc: cpp: 32,879; ansic: 2,110; makefile: 445; sh: 17
file content (111 lines) | stat: -rw-r--r-- 4,472 bytes parent folder | download | duplicates (3)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// repclone.h

/******************************************************************************
 *
 *  MiXViews - an X window system based sound & data editor/processor
 *
 *  Copyright (c) 1993, 1994 Regents of the University of California
 *
 *  Author:     Douglas Scott
 *  Date:       December 13, 1994
 *
 *  Permission to use, copy and modify this software and its documentation
 *  for research and/or educational purposes and without fee is hereby granted,
 *  provided that the above copyright notice appear in all copies and that
 *  both that copyright notice and this permission notice appear in
 *  supporting documentation. The author reserves the right to distribute this
 *  software and its documentation.  The University of California and the author
 *  make no representations about the suitability of this software for any 
 *  purpose, and in no event shall University of California be liable for any
 *  damage, loss of data, or profits resulting from its use.
 *  It is provided "as is" without express or implied warranty.
 *
 ******************************************************************************/


// RepClones are derived from DataRep subclasses and the Clone class, which
// is an encapsulation of the common redefined features of all the RepClone
// subclasses.  RepClones are created by the clone() method of the DataRep
// subclasses in response to the clone() method of the Data subclass.
//
// A RepClone is in a sense a shallow copy of the DataRep from which it comes,
// in that it contains a pointer to the same Array instance.  It also contains
// a pointer to the "master" DataRep from which it was cloned, so that under
// certain circumstances it can access the source object.  In most other ways
// these clones respond as if they were a DataRep, except they return length
// and channel count values that are subsets of the master Rep.  The key to
// their functionality is in the getAddressOfContiguousData() method, where an
// offset is added to the value based upon the location of the starting point
// of the Clone in the original master.  This allows the calling of
// modification methods upon a Data subclass clone (and hence its DataRep
// pointer member), saying in essence "process your whole self", and this will,
// via the clone's redefined methods, perform that modification upon the
// portion of the original object which was cloned to begin with.
//
// Reference counting, which is available via the Resource base class in
// InterViews, allows me to keep track of memory, and allow deletion only when
// all references are destroyed.  This happens at three levels:  the
// DataRep::Array class, the DataRep class, and the Data class.

#ifndef REPCLONE_H
#ifdef __GNUG__
#pragma interface
#endif
#define REPCLONE_H

#include "localdefs.h"
#include "datarep.h"

class Data;
class Range;

class Clone {
public:
	Clone(DataRep* mstr, int len, int chans)
		: master(mstr), cloneLen(len), cloneChans(chans) {}
	int length() const { return cloneLen; }
	int channels() const { return cloneChans; }
	void changeNChans(int);
	int read(DataFile *) {
		Application::die("Illegal operation - read() - on clone."); return 0;
	}	
	int write(DataFile *) const {
		Application::die("Illegal operation - write() - on clone."); return 0;
	}
	DataRep* clone(const Range &, const Range &) {
		Application::die("Illegal operation - clone(Range&, Range&) - on clone."); return 0;
	}	
protected:
	DataRep* master;
	int cloneLen;
	int cloneChans;
private:
	Clone(const Clone &);
};

template <class Rep>
class Cloned : public Rep, public Clone {
public:
	Cloned(Rep *, const Range &, const Range &);
	virtual ~Cloned() {}
	redefined void valueRange(Range &r, int start, int end, int chf, int chl, boolean real=false) const;
protected:
	redefined DataRep *clone(const Range& selection) {
		return Rep::clone(selection, Range(0, channels() - 1));
	}
	redefined DataRep *clone(const Range&r1, const Range&r2) {
		return Clone::clone(r1, r2);
	}
	redefined int write(DataFile *f) const { return Clone::write(f); }
	redefined int read(DataFile *f) { return Clone::read(f); }
	redefined int channels() const { return Clone::channels(); }
	redefined int length() const { return Clone::length(); }
	redefined void changeNChans(int newchans);
	redefined addr getAddressOfContiguousData() const { return (*a)[offset]; }
	redefined int changeLength(int newlen);
private:
	friend Data;
	Cloned(const Cloned&);
};

#endif /* REPCLONE_H */