ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Tree-M/MT/MTobject.h
Revision: 1.1
Committed: Sun May 6 00:45:52 2001 UTC (23 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 /*********************************************************************
2     * *
3     * Copyright (c) 1997,1998, 1999 *
4     * Multimedia DB Group and DEIS - CSITE-CNR, *
5     * University of Bologna, Bologna, ITALY. *
6     * *
7     * All Rights Reserved. *
8     * *
9     * Permission to use, copy, and distribute this software and its *
10     * documentation for NON-COMMERCIAL purposes and without fee is *
11     * hereby granted provided that this copyright notice appears in *
12     * all copies. *
13     * *
14     * THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE *
15     * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING *
16     * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, *
17     * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR *
18     * SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A *
19     * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS *
20     * DERIVATIVES. *
21     * *
22     *********************************************************************/
23    
24     #ifndef MTOBJECT_H
25     #define MTOBJECT_H
26    
27     extern int compdists;
28     extern int dimension;
29    
30     #ifndef MIN
31     #define MIN(x, y) ((x<y)? (x): (y))
32     #define MAX(x, y) ((x>y)? (x): (y))
33     #endif
34    
35     #include <stdio.h>
36     //#include <string.h>
37     #include "GiSTdefs.h"
38    
39     /*
40     typedef struct term_weight {
41     int id_term;
42     float weight;
43     struct term_weight *next;
44     } Term_Weight;
45    
46     class Object : public GiSTobject // the DB object class
47     {
48     public:
49     int tot_term;
50     Term_Weight *lst_tw;
51    
52     // long wasted_space[100]; // only for debug purposes
53    
54     Object() { // default constructor (needed)
55     tot_term=0;
56     lst_tw=NULL;
57     }
58    
59     Object(const Object& obj) { // copy constructor (needed)
60     Term_Weight **tail=&lst_tw;
61    
62     tot_term=obj.tot_term;
63     for(Term_Weight *p=obj.lst_tw; p; p=p->next) {
64     Term_Weight *m=new Term_Weight;
65    
66     m->id_term=p->id_term;
67     m->weight=p->weight;
68     *tail=m;
69     tail=&(m->next);
70     }
71     *tail=NULL;
72     }
73    
74     Object(char *key) { // member constructor (needed)
75     Term_Weight **tail=&lst_tw;
76    
77     memcpy(&tot_term, key, sizeof(int));
78     for(int i=0; i<tot_term; i++) {
79     Term_Weight *m=new Term_Weight;
80    
81     memcpy(&(m->id_term), key+sizeof(int)+i*(sizeof(int)+sizeof(float)), sizeof(int));
82     memcpy(&(m->weight), key+sizeof(int)+i*(sizeof(int)+sizeof(float))+sizeof(int), sizeof(float));
83     *tail=m;
84     tail=&(m->next);
85     }
86     *tail=NULL;
87     }
88    
89     Object(Term_Weight *p_x) { // member constructor (needed)
90     Term_Weight **tail=&lst_tw;
91    
92     tot_term=0;
93     for(Term_Weight *p=p_x; p; p=p->next) {
94     Term_Weight *m=new Term_Weight;
95    
96     m->id_term=p->id_term;
97     m->weight=p->weight;
98     tot_term++;
99     *tail=m;
100     tail=&(m->next);
101     }
102     *tail=NULL;
103     }
104    
105     ~Object() { // destructor
106     Term_Weight *p;
107    
108     for (Term_Weight *m=lst_tw; m; m=p) {
109     p=m->next;
110     delete m;
111     }
112     }
113    
114     Object& operator=(const Object& obj) { // assignment operator (needed)
115     Term_Weight *m, *p, **tail=&lst_tw;
116    
117     for (m=lst_tw; m; m=p) {
118     p=m->next;
119     delete m;
120     }
121     tot_term=obj.tot_term;
122     for(p=obj.lst_tw; p; p=p->next) {
123     m=new Term_Weight;
124     m->id_term=p->id_term;
125     m->weight=p->weight;
126     *tail=m;
127     tail=&(m->next);
128     }
129     *tail=NULL;
130     return *this;
131     }
132    
133     double area(double r) { // only needed for statistic purposes (dependent on the metric, not applicable for non-vector metric spaces)
134     return 0;
135     };
136    
137     int operator==(const Object& obj); // equality operator (needed)
138    
139     int operator!=(const Object& obj) { return !(*this==obj); }; // inequality operator (needed)
140    
141     double distance(const Object& other) const; // distance method (needed)
142     int CompressedLength() const; // return the compressed size of this object
143     void Compress(char *key) { // object compression
144     int i=0;
145    
146     memcpy(key, &tot_term, sizeof(int));
147     for(Term_Weight *p=lst_tw; p; p=p->next) {
148     memcpy(key+sizeof(int)+i*(sizeof(int)+sizeof(float)), &(p->id_term), sizeof(int));
149     memcpy(key+sizeof(int)+i*(sizeof(int)+sizeof(float))+sizeof(int), &(p->weight), sizeof(float));
150     i++;
151     }
152     }
153    
154     #ifdef PRINTING_OBJECTS
155     void Print(ostream& os) const;
156     #endif
157     };
158    
159     double maxDist(); // return the maximum value for the distance between two objects
160     int sizeofObject(); // return the compressed size of each object (0 if objects have different sizes)
161    
162     Object *Read(); // read an object from standard input
163     Object *Read(FILE *fp); // read an object from a file
164     */
165    
166     #include "../object.h"
167    
168     #endif