1 /* === S I N F G =========================================================== */
3 ** \brief Template File
5 ** $Id: keyframe.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
33 #include <ETL/stringf>
36 #include "exception.h"
42 /* === U S I N G =========================================================== */
46 using namespace sinfg;
48 /* === M A C R O S ========================================================= */
50 /* === G L O B A L S ======================================================= */
52 /* === P R O C E D U R E S ================================================= */
54 /* === M E T H O D S ======================================================= */
61 Keyframe::Keyframe(const Time &time):
71 KeyframeList::dump()const
75 sinfg::info(">>>>>>>>BEGIN KEYFRAME DUMP");
76 for(iter=begin(),i=0;iter!=end();++iter,i++)
78 sinfg::info("#%d, time: %s, desc: %s",i,iter->get_time().get_string().c_str(),iter->get_description().c_str());
80 sinfg::info("<<<<<<<<END KEYFRAME DUMP");
87 //sinfg::info("PRE-SORT:");
90 //sinfg::info("POST-SORT:");
95 KeyframeList::iterator
96 KeyframeList::find(const UniqueID &x)
98 KeyframeList::iterator iter;
99 iter=std::find(begin(),end(),x);
101 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find UniqueID %d",x.get_uid()));
105 KeyframeList::const_iterator
106 KeyframeList::find(const UniqueID &x)const
108 KeyframeList::const_iterator iter;
109 iter=std::find(begin(),end(),x);
111 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find UniqueID %d",x.get_uid()));
115 KeyframeList::iterator
116 KeyframeList::add(const Keyframe &x)
127 KeyframeList::erase(const UniqueID &x)
129 std::vector<Keyframe>::erase(find(x));
132 KeyframeList::iterator
133 KeyframeList::find(const Time &x)
135 KeyframeList::iterator iter;
136 iter=binary_find(begin(),end(),x);
137 if(iter!=end() && iter->get_time().is_equal(x))
140 if(iter!=end() && iter->get_time().is_equal(x))
143 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find Keyframe %s",x.get_string().c_str()));
146 KeyframeList::iterator
147 KeyframeList::find_next(const Time &x)
149 KeyframeList::iterator iter(binary_find(begin(),end(),x));
153 if(iter->get_time().is_more_than(x))
158 if(iter->get_time().is_more_than(x))
161 if(iter!=end() && iter->get_time().is_more_than(x))
167 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find next Keyframe %s",x.get_string().c_str()));
171 KeyframeList::iterator
172 KeyframeList::find_prev(const Time &x)
174 KeyframeList::iterator iter(binary_find(begin(),end(),x));
178 if(iter->get_time()+Time::epsilon()<x)
180 if(iter!=begin() && (--iter)->get_time()+Time::epsilon()<x)
183 throw Exception::NotFound(strprintf("KeyframeList::find(): Can't find prev Keyframe %s",x.get_string().c_str()));
189 KeyframeList::const_iterator
190 KeyframeList::find(const Time &x)const
192 return const_cast<KeyframeList*>(this)->find(x);
196 KeyframeList::const_iterator
197 KeyframeList::find_next(const Time &x)const
199 return const_cast<KeyframeList*>(this)->find_next(x);
204 KeyframeList::const_iterator
205 KeyframeList::find_prev(const Time &x)const
207 return const_cast<KeyframeList*>(this)->find_prev(x);
212 KeyframeList::find_prev_next(const Time& time, Time &prev, Time &next)const
214 try { prev=find_prev(time)->get_time(); }
215 catch(...) { prev=Time::begin(); }
216 try { next=find_next(time)->get_time(); }
217 catch(...) { next=Time::end(); }
221 KeyframeList::insert_time(const Time& location, const Time& delta)
223 // sinfg::info("KeyframeList::insert_time(): loc=%s, delta=%s",location.get_string().c_str(),delta.get_string().c_str());
228 iterator iter(find_next(location));
229 for(;iter!=end();++iter)
231 iter->set_time(iter->get_time()+delta);
235 catch(Exception::NotFound) { }