00001 #ifndef INCLUDE_PARTIAL_H
00002 #define INCLUDE_PARTIAL_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "Breakpoint.h"
00040 #include "LorisExceptions.h"
00041
00042 #include <map>
00043
00044
00045
00046
00047 namespace Loris {
00048
00049 class Partial_Iterator;
00050 class Partial_ConstIterator;
00051
00052
00053
00054
00092
00093 class Partial
00094 {
00095
00096 public:
00097
00098
00099
00102 typedef std::map< double, Breakpoint > container_type;
00103
00104
00105
00106
00107
00109 typedef int label_type;
00110
00112 typedef Partial_Iterator iterator;
00113
00115 typedef Partial_ConstIterator const_iterator;
00116
00118 typedef container_type::size_type size_type;
00119
00120
00121
00123 Partial( void );
00124
00132 Partial( const_iterator beg, const_iterator end );
00133
00139 Partial( const Partial & other );
00140
00142 ~Partial( void );
00143
00144
00145
00151 Partial & operator=( const Partial & other );
00152
00153
00154
00158 iterator begin( void );
00159
00163 const_iterator begin( void ) const;
00164
00169 iterator end( void );
00170
00175 const_iterator end( void ) const;
00176
00186 iterator erase( iterator beg, iterator end );
00187
00196 iterator findAfter( double time );
00197
00206 const_iterator findAfter( double time ) const;
00207
00217 iterator insert( double time, const Breakpoint & bp );
00218
00222 size_type size( void ) const;
00223
00224
00225
00230 double duration( void ) const;
00231
00236 double endTime( void ) const;
00237
00242 Breakpoint & first( void );
00243
00248 const Breakpoint & first( void ) const;
00249
00254 double initialPhase( void ) const;
00255
00257 label_type label( void ) const;
00258
00263 Breakpoint & last( void );
00264
00269 const Breakpoint & last( void ) const;
00270
00272 size_type numBreakpoints( void ) const;
00273
00278 double startTime( void ) const;
00279
00280
00281
00288 void absorb( const Partial & other );
00289
00291 void setLabel( label_type l );
00292
00303 iterator erase( iterator pos );
00304
00311 iterator findNearest( double time );
00312
00319 const_iterator findNearest( double time ) const;
00320
00333 Partial split( iterator pos );
00334
00335
00336
00344 static const double ShortestSafeFadeTime;
00345
00360 double amplitudeAt( double time, double fadeTime = ShortestSafeFadeTime ) const;
00361
00372 double bandwidthAt( double time ) const;
00373
00383 double frequencyAt( double time ) const;
00384
00395 double phaseAt( double time ) const;
00396
00414 Breakpoint parametersAt( double time, double fadeTime = ShortestSafeFadeTime ) const;
00415
00416
00417 private:
00418
00419 label_type _label;
00420 container_type _breakpoints;
00421
00422 };
00423
00424
00425
00426
00433
00434 class Partial_Iterator
00435 {
00436
00437
00438 typedef Partial::container_type BaseContainer;
00439 typedef BaseContainer::iterator BaseIterator;
00440 BaseIterator _iter;
00441
00442
00443 public:
00444
00445
00448 typedef BaseIterator::iterator_category iterator_category;
00449
00452 typedef Breakpoint value_type;
00453
00456 typedef BaseIterator::difference_type difference_type;
00457
00460 typedef Breakpoint * pointer;
00461
00464 typedef Breakpoint & reference;
00465
00466
00467
00470 Partial_Iterator( void ) {}
00471
00472
00473
00474
00475
00482 Partial_Iterator& operator ++ () { ++_iter; return *this; }
00483
00490 Partial_Iterator& operator -- () { --_iter; return *this; }
00491
00492
00493
00502 Partial_Iterator operator ++ ( int ) { return Partial_Iterator( _iter++ ); }
00503
00512 Partial_Iterator operator -- ( int ) { return Partial_Iterator( _iter-- ); }
00513
00514
00515
00516
00521 Breakpoint & operator * ( void ) const { return breakpoint(); }
00522
00523
00528
00529
00534 Breakpoint * operator -> ( void ) const { return & breakpoint(); }
00535
00540
00541
00542
00543
00550 friend bool operator == ( const Partial_Iterator & lhs,
00551 const Partial_Iterator & rhs )
00552 { return lhs._iter == rhs._iter; }
00553
00560 friend bool operator != ( const Partial_Iterator & lhs,
00561 const Partial_Iterator & rhs )
00562 { return lhs._iter != rhs._iter; }
00563
00564
00565
00570 Breakpoint & breakpoint( void ) const
00571 { return _iter->second; }
00572
00577
00578
00579
00584 double time( void ) const
00585 { return _iter->first; }
00586
00587
00588 private:
00589
00590 Partial_Iterator( const BaseIterator & it ) :
00591 _iter(it) {}
00592
00593 friend class Partial;
00594
00595
00596
00597 friend class Partial_ConstIterator;
00598
00599 };
00600
00601
00602
00603
00610
00611 class Partial_ConstIterator
00612 {
00613
00614 typedef Partial::container_type BaseContainer;
00615 typedef BaseContainer::const_iterator BaseIterator;
00616 BaseIterator _iter;
00617
00618
00619 public:
00620
00621
00624 typedef BaseIterator::iterator_category iterator_category;
00625
00628 typedef Breakpoint value_type;
00629
00632 typedef BaseIterator::difference_type difference_type;
00633
00636 typedef const Breakpoint * pointer;
00637
00640 typedef const Breakpoint & reference;
00641
00642
00643
00646 Partial_ConstIterator( void ) {}
00647
00652 Partial_ConstIterator( const Partial_Iterator & other ) :
00653 _iter( other._iter ) {}
00654
00655
00656
00657
00658
00665 Partial_ConstIterator& operator ++ () { ++_iter; return *this; }
00666
00673 Partial_ConstIterator& operator -- () { --_iter; return *this; }
00674
00675
00676
00685 Partial_ConstIterator operator ++ ( int ) { return Partial_ConstIterator( _iter++ ); }
00686
00695 Partial_ConstIterator operator -- ( int ) { return Partial_ConstIterator( _iter-- ); }
00696
00697
00698
00699
00704 const Breakpoint & operator * ( void ) const { return breakpoint(); }
00705
00710 const Breakpoint * operator -> ( void ) const { return & breakpoint(); }
00711
00712
00713
00720 friend bool operator == ( const Partial_ConstIterator & lhs,
00721 const Partial_ConstIterator & rhs )
00722 { return lhs._iter == rhs._iter; }
00723
00730 friend bool operator != ( const Partial_ConstIterator & lhs,
00731 const Partial_ConstIterator & rhs )
00732 { return lhs._iter != rhs._iter; }
00733
00734
00735
00740 const Breakpoint & breakpoint( void ) const
00741 { return _iter->second; }
00742
00747 double time( void ) const
00748 { return _iter->first; }
00749
00750
00751 private:
00752
00753 Partial_ConstIterator( BaseIterator it ) :
00754 _iter(it) {}
00755
00756 friend class Partial;
00757
00758 };
00759
00760
00761
00762
00765
00766 class InvalidPartial : public InvalidObject
00767 {
00768 public:
00769
00779 InvalidPartial( const std::string & str, const std::string & where = "" ) :
00780 InvalidObject( std::string("Invalid Partial -- ").append( str ), where ) {}
00781
00782 };
00783
00784 }
00785
00786 #endif