diff --git a/pub/src/manip.cpp b/pub/src/manip.cpp index d1bbf49693376dd6b090ef7eae638f7ef7504a5b..62866184a3346558918541d9a079fd14078ff6f1 100644 --- a/pub/src/manip.cpp +++ b/pub/src/manip.cpp @@ -85,7 +85,7 @@ void NManip::PtsSelect( bool sel_del ) for ( uint j=0; j<fin->nJ(); j++ ) { PSpec sin = fin->VS(j); PSpec sout( new CSpec ); - sout->copy_zentry( sin ); + sout->copy_z_base( sin ); pLis.evaluate( 0, sin->size()-1 ); for ( uint i=0; i<sin->size(); i++ ) { if ( sel_del ^ pLis.contains(i) ) { @@ -125,7 +125,7 @@ void NManip::PtsAvge() for( uint j=0; j<fin->nJ(); j++ ) { PSpec sin = fin->VS(j); PSpec sout( new CSpec() ); - sout->copy_zentry( sin ); + sout->copy_z_base( sin ); IndexSet Groups; if (Groups.parse(groups, 0, sin->size())) @@ -184,7 +184,7 @@ void NManip::PtsSort() for ( uint j=0; j<fin->nJ(); j++ ) { PSpec sin = fin->VS(j); PSpec sout( new CSpec ); - sout->copy_zentry( sin ); + sout->copy_z_base( sin ); n = sin->size(); vector<double> v(n); @@ -223,7 +223,7 @@ void NManip::PtsAvgeEq(void) for ( uint j=0; j<fin->nJ(); j++ ) { const PSpec sin = fin->VS(j); PSpec sout( new CSpec ); - sout->copy_zentry( sin ); + sout->copy_z_base( sin ); uint n = sin->size(); uint ii=0; @@ -277,7 +277,7 @@ void NManip::PtsSymmetrize() for (uint j=0; j<fin->nJ(); j++) { PSpec sin = fin->VS(j); PSpec sout( new CSpec ); - sout->copy_zentry( sin ); + sout->copy_z_base( sin ); if( mystd::sorted( sin->x )!=1 ) throw string( "not sorted" ); double step; @@ -1017,13 +1017,10 @@ void NManip::FilMergePointwise() NOlm::IterateD fiter; POld fin = fiter(); + POld fout( new COld( *fin ) ); - fout->V.clear(); - for ( uint j=0; j<fin->nJ(); ++j ) { - PSpec sin = fin->VS(j); - PSpec sout( new CSpec( *sin ) ); - fout->V.push_back( sout ); - } + fout->copy_mainvec( fin ); + while ( fin = fiter() ) { if ( fin->nJ() != fout->nJ() ) throw string( "different # spectra" ); diff --git a/pub/src/mem.cpp b/pub/src/mem.cpp index b00afc41d66a0f74148413e6e4f5f23efdd1cb1a..c9c0ea7cb70249f29e4f57af8c8a17f21904097e 100644 --- a/pub/src/mem.cpp +++ b/pub/src/mem.cpp @@ -103,7 +103,7 @@ void NOlm::OlfCopy() POlo fin; while ( (fin=fiter()) ){ POlo fout( fin->new_olo() ); - // TODO copy z + fout->copy_mainvec( fin ); OloAdd( fout ); } } diff --git a/pub/src/olf.cpp b/pub/src/olf.cpp index f646d8285402f9115860c8b97db72327268b7a12..a801e7f68a59b0890a78390c16fcad308c332110 100644 --- a/pub/src/olf.cpp +++ b/pub/src/olf.cpp @@ -19,10 +19,8 @@ using namespace std; //***************************************************************************// //* class COld *// -//* online data files *// //***************************************************************************// - COld::COld( class COlc const* c ) { name = c->name; @@ -51,16 +49,73 @@ uint COld::nPts() const { return np; } -boost::shared_ptr<class COlo> COld::new_olo() const + +//***************************************************************************// +//* trivially duplicated COld/COlc functions *// +//***************************************************************************// + + +//! New shared pointer to copied spec/curve. + +PZentry COld::new_zentry( uint j ) const +{ + return PZentry( new CSpec( *(VS(j)) ) ); +} + +PZentry COlc::new_zentry( uint j ) const +{ + return PZentry( new CCurve( *(VC(j)) ) ); +} + + +//! New shared pointer to copied online file (but without copying main vector). + +POlo COld::new_olo() const { POlo ret( new COld( *this ) ); ret->V.clear(); return ret; } -boost::shared_ptr<class COlo> COlc::new_olo() const +POlo COlc::new_olo() const { POlo ret( new COlc( *this ) ); ret->V.clear(); return ret; } + + +//! Set main vector by copying from fin. + +void COld::copy_mainvec( POlo fin ) +{ + POld fd = boost::dynamic_pointer_cast<class COld>( fin ); + for( uint j=0; j<fin->nJ(); ++j ) + V[j] = PZentry( new CSpec( *(fd->VS(j)) ) ); +} + +void COlc::copy_mainvec( POlo fin ) +{ + POlc fc = boost::dynamic_pointer_cast<class COlc>( fin ); + for( uint j=0; j<fin->nJ(); ++j ) + V[j] = PZentry( new CCurve( *(fc->VC(j)) ) ); +} + + +//! Return pointer to selected main vector entry: + +PSpec COld::VS( uint j ) const +{ + PSpec p = boost::dynamic_pointer_cast<class CSpec>( V[j] ); + if ( !p ) + throw string( "invalid VS call" ); + return p; +} + +PCurve COlc::VC( uint j ) const +{ + PCurve p = boost::dynamic_pointer_cast<class CCurve>( V[j] ); + if ( !p ) + throw string( "invalid VC call" ); + return p; +} diff --git a/pub/src/olf.h b/pub/src/olf.h index f95e1723bb1eb513bd28630380a2b070736625bd..584d31588410f7e3b4e2e7b860d9c6d136d67913 100644 --- a/pub/src/olf.h +++ b/pub/src/olf.h @@ -4,6 +4,14 @@ #include "coord.h" #include "zentry.h" + +//! Shared pointers, used in function declarations. + +typedef boost::shared_ptr<class COlo> POlo; +typedef boost::shared_ptr<class COld> POld; +typedef boost::shared_ptr<class COlc> POlc; + + //! Online object: virtual base class for COld, COlc. class COlo { @@ -29,12 +37,13 @@ class COlo { for( uint j=0; j<nJ(); ++j ) V[j]->z.erase( V[j]->z.begin()+iz ); }; + virtual void copy_mainvec( POlo fin ) = 0; uint nJ() const { return V.size(); }; uint nZ() const { return ZCo.size(); }; double z( uint j, uint iz ) const { return V[j]->z[iz]; }; virtual PZentry new_zentry( uint j ) const = 0; - virtual boost::shared_ptr<class COlo> new_olo() const = 0; + virtual POlo new_olo() const = 0; }; @@ -45,22 +54,16 @@ class COld : public COlo { COld() {}; COld( class COlc const* fc ); - PSpec VS( uint j ) const { - PSpec p = boost::dynamic_pointer_cast<CSpec>( V[j] ); - if ( !p ) - throw string( "invalid VS call" ); - return p; - } - - void remove_z( uint iz ){ - COlo::remove_z( iz ); - }; + // trivially duplicated functions: + PSpec VS( uint j ) const; +// void remove_z( uint iz ){ COlo::remove_z( iz ); }; + PZentry new_zentry( uint j ) const; + POlo new_olo() const; + void copy_mainvec( POlo fin ); + // pertinent functions: uint nPts(uint j) const; uint nPts() const; // 0 unless all spectra j have same nPts(j) - PZentry new_zentry( uint j ) const { - return PZentry( new CSpec( *(VS(j)) ) ); }; - boost::shared_ptr<class COlo> new_olo() const; }; @@ -72,13 +75,6 @@ class COlc : public COlo { string expr; vector<CCoord> PCo; - PCurve VC( uint j ) const { - PCurve p = boost::dynamic_pointer_cast<CCurve>( V[j] ); - if ( !p ) - throw string( "invalid VC call" ); - return p; - } - // online state records: boost::shared_ptr<class CTree> T; vector<CList> Fixed; @@ -91,20 +87,20 @@ class COlc : public COlo { COlc() : weight_y_log(false), kconv(-1) { ; }; + // trivially duplicated functions: + PCurve VC( uint j ) const; + PZentry new_zentry( uint j ) const; + POlo new_olo() const; + void copy_mainvec( POlo fin ); + + // pertinent functions: uint nPar() const { return PCo.size(); }; vector<string> pInfo() const; string pInfoCat() const; - PZentry new_zentry( uint j ) const { - return PZentry( new CCurve( *(VC(j)) ) ); }; - boost::shared_ptr<class COlo> new_olo() const; }; -//! Element of online memory: pointer to COlo,... - -typedef boost::shared_ptr<COlo> POlo; -typedef boost::shared_ptr<COld> POld; -typedef boost::shared_ptr<COlc> POlc; +//! Casts. #define P2D(p) boost::dynamic_pointer_cast<COld>(p) #define P2C(p) boost::dynamic_pointer_cast<COlc>(p) diff --git a/pub/src/opr.cpp b/pub/src/opr.cpp index 16a2a00a47599af48cde452c94b0a8925e1162d4..28381fed437d5e2001276a1da8993ef87a689b2d 100644 --- a/pub/src/opr.cpp +++ b/pub/src/opr.cpp @@ -116,7 +116,7 @@ void NOperate::Select( bool sel_del ) if ( fd ) { PSpec ein = fd->VS(j); PSpec eout = PSpec( new CSpec ); - eout->copy_zentry( ein ); + eout->copy_z_base( ein ); vector<double> lvec( ein->size() ); T->tree_vec_val( &lvec, fiter.k(), j ); bool with_dy = ein->dy.size(); diff --git a/pub/src/zentry.cpp b/pub/src/zentry.cpp index 4e96c281ca536cc1df50494b47d5245041915e7f..bb7d0b805e5f3d1a721a75f89743452d34ac707e 100644 --- a/pub/src/zentry.cpp +++ b/pub/src/zentry.cpp @@ -25,7 +25,7 @@ using namespace std; //! Partial copy, to initialize a new Zentry from an existing one. -void CZentry::copy_zentry( PZentry ein ) +void CZentry::copy_z_base( PZentry ein ) { z = ein->z; dz = ein->dz; diff --git a/pub/src/zentry.h b/pub/src/zentry.h index 8421718b2e9b234621249d549822aac197cf0638..564a4873e5af84c213ac3a6cc2876ca2c73c9cfa 100644 --- a/pub/src/zentry.h +++ b/pub/src/zentry.h @@ -10,7 +10,7 @@ class CZentry { virtual ~CZentry() {}; // magic: makes dynamic_cast possible - void copy_zentry( boost::shared_ptr<class CZentry> ein ); + void copy_z_base( boost::shared_ptr<class CZentry> ein ); };