CLAM-Development  1.4.0
SDIFCollection.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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 #include "SDIFCollection.hxx"
23 #include "SDIFFrame.hxx"
24 #include "SDIFStream.hxx"
25 #include "SDIFMatrix.hxx"
26 
27 namespace SDIF
28 {
29 
30  Collection::Collection(bool autoStreamAdding)
31  :mAutoStreamAdding(autoStreamAdding)
32  {
33  }
34 
35  void Collection::Add(Frame* pFrame)
36  {
37  mFrameList.push_back(pFrame);
38 
39  if (mAutoStreamAdding) {
40  Stream* pStream = FindStream(pFrame->mHeader.mStreamId);
41  if (!pStream)
42  {
43  pStream =
44  new Stream(pFrame->mHeader.mType,pFrame->mHeader.mStreamId);
45  Add(pStream);
46  }
47  CLAM_ASSERT(pFrame->mHeader.mType==pStream->StreamType(),
48  "Trying to add a frame to a stream with the same ID but a different type");
49  pStream->Add(pFrame);
50  }
51  }
52 
53  void Collection::Add(Stream* pStream)
54  {
55  mStreamList.push_back(pStream);
56  }
57 
59  {
60  typedef std::list<Frame*>::iterator iterator;
61 
62  iterator it = mFrameList.begin();
63  iterator end = mFrameList.end();
64 
65  while (it!=end)
66  {
67  Frame* pFrame = *it;
68 
69  Stream* pStream = FindStream(pFrame->mHeader.mStreamId);
70  if (!pStream) {
71  pStream =
72  new Stream(pFrame->mHeader.mType,pFrame->mHeader.mStreamId);
73 
74  Add(pStream);
75  }
76  pStream->Add(pFrame);
77 
78  it++;
79  }
80  }
81 
83  {
84  typedef std::list<Stream*>::iterator iterator;
85 
86  iterator it = mStreamList.begin();
87  iterator end = mStreamList.end();
88 
89  while (it!=end)
90  {
91  Stream* pStream = *it;
92  if (pStream->StreamId()==streamId) return pStream;
93 
94  it++;
95  }
96 
97  return 0;
98  }
99 
101  {
102  typedef std::list<Stream*>::iterator iterator;
103 
104  iterator it = mStreamList.begin();
105  iterator end = mStreamList.end();
106 
107  while (it!=end)
108  {
109  Stream* pStream = *it;
110  if (pStream->StreamType()==streamTypeId) return pStream;
111 
112  it++;
113  }
114 
115  return 0;
116  }
117 
118 
119 }
120