CLAM-Development  1.4.0
Fundamental.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #ifndef _Fundamental_
23 #define _Fundamental_
24 #include <typeinfo>
25 #include "DynamicType.hxx"
26 #include "Array.hxx"
27 #include "DataTypes.hxx"
28 #include "OSDefines.hxx"
29 #include "Err.hxx"
30 #include "ProcessingData.hxx"
31 
32 namespace CLAM
33 {
34 
36  // Class Fundamental:
37  //
38 
44  class Fundamental : public ProcessingData
45  {
46  public:
49  DYN_ATTRIBUTE (0, public, DataArray, CandidatesFreq);
51  DYN_ATTRIBUTE (1, public, DataArray, CandidatesErr);
52 
53  protected:
54  void DefaultInit();
55 
56  public:
57  void SetnMaxCandidates(TSize nMaxCandidates)
58  {
59  if (HasCandidatesFreq())
60  GetCandidatesFreq().Resize(nMaxCandidates);
61 
62  if (HasCandidatesErr())
63  GetCandidatesErr().Resize(nMaxCandidates);
64  }
65 
67  {
68  if (HasCandidatesFreq())
69  return GetCandidatesFreq().AllocatedSize();
70 
71  if (HasCandidatesErr())
72  return GetCandidatesErr().AllocatedSize();
73 
74  return 0;
75  }
76 
77  void SetnCandidates(int size)
78  {
79  if (HasCandidatesFreq())
80  GetCandidatesFreq().SetSize(size);
81 
82  if (HasCandidatesErr())
83  GetCandidatesErr().SetSize(size);
84  }
85 
86  int GetnCandidates() const
87  {
88  if (HasCandidatesFreq())
89  return GetCandidatesFreq().Size();
90 
91  if (HasCandidatesErr())
92  return GetCandidatesErr().Size();
93 
94  return 0;
95  }
96 
102  TData GetFreq(TIndex pos=0) const;
103 
108  TData GetErr(TIndex pos=0) const;
109 
110 
115  void SetFreq(TIndex pos,TData newFreq);
116 
121  void SetErr(TIndex pos,TData newErr);
122 
123  // Other functionality
124 
129  void AddElem (TData freq=0.f, TData err=0.f);
130 
136  void InsertElem (TIndex pos, TData freq=0.f, TData err=0.f);
137 
141  void DeleteElem (TIndex pos);
142 
143 
144  // Ordering functions
145 
150  void SortByFrequency();
151 
156  void SortByError();
157 
159  void Init()
160  {
161  GetCandidatesFreq().SetSize(0);
162  GetCandidatesErr().SetSize(0);
163  SetnCandidates(0);
164  }
165  };
166 
167 } // namespace CLAM
168 
169 #endif
170