[med-svn] [aghermann] 78/85: whitespace; prefer const string& type for a fname arg; rename CHypnogram::{->n_}pages
andrei zavada
hmmr-guest at alioth.debian.org
Thu Sep 26 23:46:36 UTC 2013
This is an automated email from the git hooks/post-receive script.
hmmr-guest pushed a commit to branch master
in repository aghermann.
commit d9dd2c6fccdc55b69c2fad98634471fac7b21168
Author: Andrei Zavada <johnhommer at gmail.com>
Date: Thu Sep 26 02:44:23 2013 +0300
whitespace; prefer const string& type for a fname arg; rename CHypnogram::{->n_}pages
---
upstream/src/aghermann/expdesign/recording.cc | 10 +++---
upstream/src/aghermann/rk1968/rk1968.cc | 4 +--
upstream/src/aghermann/ui/sf/hypnogram.cc | 2 +-
upstream/src/aghermann/ui/sf/sf.cc | 35 ++++++++++---------
upstream/src/libsigfile/page.cc | 44 +++++++++++++-----------
upstream/src/libsigfile/page.hh | 45 ++++++++++++-------------
upstream/src/libsigfile/typed-source.cc | 6 ++--
7 files changed, 75 insertions(+), 71 deletions(-)
diff --git a/upstream/src/aghermann/expdesign/recording.cc b/upstream/src/aghermann/expdesign/recording.cc
index be4c0ab..ac36ac3 100644
--- a/upstream/src/aghermann/expdesign/recording.cc
+++ b/upstream/src/aghermann/expdesign/recording.cc
@@ -118,14 +118,14 @@ CProfile (CSubject& J, const string& d, const sigfile::SChannel& h,
return; // this is really serious, so return now
}
- int pa = (size_t)difftime( F.start_time(), _0at) / _pagesize,
-// pz = (size_t)difftime( F.end_time(), _0at) / _pagesize;
- pz = pa + M.hypnogram().pages();
+ int pa = (size_t)difftime( F.start_time(), _0at) / _pagesize,
+ //pz = (size_t)difftime( F.end_time(), _0at) / _pagesize;
+ pz = pa + M.hypnogram().n_pages();
// anchor zero page, get pagesize from edf^W CBinnedPower^W either goes
time_t dima = F.start_time();
printf( "CProfile::CProfile(): adding %s of [%s, %s, %s] %zu pages (%zu full, %zu in hypnogram) recorded %s",
metrics::name(params.metric), F.subject().id.c_str(), F.session(), F.episode(),
- M.total_pages(), M.full_pages(), M.hypnogram().pages(), ctime( &dima));
+ M.total_pages(), M.full_pages(), M.hypnogram().n_pages(), ctime( &dima));
if ( pz - pa != (int)M.full_pages() ) {
fprintf( stderr, "CProfile::CProfile(): correcting end page to match full page count in EDF: %d->%zu\n",
@@ -180,7 +180,7 @@ CProfile (CRecording& M,
time_t dima = M.F().start_time();
printf( "CProfile::CProfile(): adding single recording %s of [%s, %s, %s] %zu pages (%zu full, %zu in hypnogram) recorded %s",
metrics::name(params.metric), M.F().subject().id.c_str(), M.F().session(), M.F().episode(),
- M.total_pages(), M.full_pages(), M.hypnogram().pages(), ctime( &dima));
+ M.total_pages(), M.full_pages(), M.hypnogram().n_pages(), ctime( &dima));
if ( pz - pa != (int)M.full_pages() ) {
fprintf( stderr, "CProfile::CProfile(): correcting end page to match full page count in EDF: %d->%zu\n",
diff --git a/upstream/src/aghermann/rk1968/rk1968.cc b/upstream/src/aghermann/rk1968/rk1968.cc
index 43fb53f..26e49d3 100644
--- a/upstream/src/aghermann/rk1968/rk1968.cc
+++ b/upstream/src/aghermann/rk1968/rk1968.cc
@@ -64,8 +64,8 @@ score( agh::SEpisode& E)
}
auto& firstsource = E.sources.front();
- for ( size_t p = 0; p < firstsource.pages(); ++p ) {
- auto Di = courses_delta.begin(),
+ for ( size_t p = 0; p < firstsource.n_pages(); ++p ) {
+ auto Di = courses_delta.begin(),
Ti = courses_theta.begin();
int decision = 0;
for ( ; Di != courses_delta.end(); ++Di, ++Ti )
diff --git a/upstream/src/aghermann/ui/sf/hypnogram.cc b/upstream/src/aghermann/ui/sf/hypnogram.cc
index e7ec6a6..e4f51c1 100644
--- a/upstream/src/aghermann/ui/sf/hypnogram.cc
+++ b/upstream/src/aghermann/ui/sf/hypnogram.cc
@@ -146,7 +146,7 @@ do_dialog_import_hypnogram()
size_t c = 0;
while ( not getline(f, t).eof() )
++c;
- size_t our_pages = sepisode().sources.front().pages();
+ size_t our_pages = sepisode().sources.front().n_pages();
if ( c != our_pages && // allow for last page scored but discarded in CHypnogram as incomplete
c != our_pages+1 )
pop_ok_message(
diff --git a/upstream/src/aghermann/ui/sf/sf.cc b/upstream/src/aghermann/ui/sf/sf.cc
index 47cd356..e7e25f1 100644
--- a/upstream/src/aghermann/ui/sf/sf.cc
+++ b/upstream/src/aghermann/ui/sf/sf.cc
@@ -460,8 +460,8 @@ get_hypnogram()
// just get from the first source,
// trust other sources are no different
auto &F = _sepisode.sources.front();
- hypnogram.resize( F.sigfile::CHypnogram::pages());
- for ( size_t p = 0; p < F.pages(); ++p )
+ hypnogram.resize( F.sigfile::CHypnogram::n_pages());
+ for ( size_t p = 0; p < F.n_pages(); ++p )
hypnogram[p] = F[p].score_code();
}
void
@@ -470,7 +470,7 @@ put_hypnogram()
{
// but put to all
for( auto &F : _sepisode.sources )
- for ( size_t p = 0; p < F.sigfile::CHypnogram::pages(); ++p )
+ for ( size_t p = 0; p < F.sigfile::CHypnogram::n_pages(); ++p )
F[p].mark( hypnogram[p]);
}
@@ -483,21 +483,24 @@ calculate_scored_percent()
{
using namespace sigfile;
scored_percent_nrem =
- (float)count_if( hypnogram.begin(), hypnogram.end(),
- [] ( const char& c)
- {
- return
- c == SPage::score_code(SPage::TScore::nrem1)
- || c == SPage::score_code(SPage::TScore::nrem2)
- || c == SPage::score_code(SPage::TScore::nrem3)
- || c == SPage::score_code(SPage::TScore::nrem4);
- }) / hypnogram.size() * 100;
+ (float)count_if(
+ hypnogram.begin(), hypnogram.end(),
+ [] ( const char& c)
+ {
+ return
+ c == SPage::score_code(SPage::TScore::nrem1)
+ || c == SPage::score_code(SPage::TScore::nrem2)
+ || c == SPage::score_code(SPage::TScore::nrem3)
+ || c == SPage::score_code(SPage::TScore::nrem4);
+ }) / hypnogram.size() * 100;
scored_percent_rem =
- (float)count( hypnogram.begin(), hypnogram.end(),
- SPage::score_code(SPage::TScore::rem)) / hypnogram.size() * 100;
+ (float)count(
+ hypnogram.begin(), hypnogram.end(),
+ SPage::score_code(SPage::TScore::rem)) / hypnogram.size() * 100;
scored_percent_wake =
- (float)count( hypnogram.begin(), hypnogram.end(),
- SPage::score_code(SPage::TScore::wake)) / hypnogram.size() * 100;
+ (float)count(
+ hypnogram.begin(), hypnogram.end(),
+ SPage::score_code(SPage::TScore::wake)) / hypnogram.size() * 100;
scored_percent =
100. - count(
diff --git a/upstream/src/libsigfile/page.cc b/upstream/src/libsigfile/page.cc
index da1fb73..66f8afc 100644
--- a/upstream/src/libsigfile/page.cc
+++ b/upstream/src/libsigfile/page.cc
@@ -41,24 +41,28 @@ sigfile::CHypnogram::
percent_scored( float *nrem_p, float *rem_p, float *wake_p) const
{
if ( nrem_p )
- *nrem_p = (float)count_if( _pages.begin(), _pages.end(),
- mem_fun_ref (&SPage::is_nrem)) / _pages.size() * 100;
+ *nrem_p = (float)count_if(
+ _pages.begin(), _pages.end(),
+ mem_fun_ref (&SPage::is_nrem)) / _pages.size() * 100;
if ( rem_p )
- *rem_p = (float)count_if( _pages.begin(), _pages.end(),
- mem_fun_ref (&SPage::is_rem)) / _pages.size() * 100;
+ *rem_p = (float)count_if(
+ _pages.begin(), _pages.end(),
+ mem_fun_ref (&SPage::is_rem)) / _pages.size() * 100;
if ( wake_p )
- *wake_p = (float)count_if( _pages.begin(), _pages.end(),
- mem_fun_ref (&SPage::is_wake)) / _pages.size() * 100;
+ *wake_p = (float)count_if(
+ _pages.begin(), _pages.end(),
+ mem_fun_ref (&SPage::is_wake)) / _pages.size() * 100;
- return (float)count_if( _pages.begin(), _pages.end(),
- mem_fun_ref (&SPage::is_scored)) / _pages.size() * 100;
+ return (float)count_if(
+ _pages.begin(), _pages.end(),
+ mem_fun_ref (&SPage::is_scored)) / _pages.size() * 100;
}
sigfile::CHypnogram::TError
sigfile::CHypnogram::
-save( const char* fname) const
+save( const string& fname) const
{
ofstream of (fname, ios_base::trunc);
if ( not of.good() )
@@ -74,22 +78,22 @@ save( const char* fname) const
sigfile::CHypnogram::TError
sigfile::CHypnogram::
-load( const char* fname)
+load( const string& fname)
{
ifstream f (fname);
if ( not f.good() )
return CHypnogram::TError::nofile;
- SPage P;
+ SPage P;
- size_t saved_pagesize;
+ size_t saved_pagesize;
f >> saved_pagesize;
if ( not f.good() )
return CHypnogram::TError::baddata;
if ( saved_pagesize != _pagesize ) {
fprintf( stderr, "CHypnogram::load(\"%s\"): read pagesize (%zu) different from that specified at construct (%zu)\n",
- fname, saved_pagesize, _pagesize);
+ fname.c_str(), saved_pagesize, _pagesize);
_pagesize = saved_pagesize;
return CHypnogram::TError::wrongpagesize;
}
@@ -107,14 +111,14 @@ load( const char* fname)
int
sigfile::CHypnogram::
-save_canonical( const char *fname) const
+save_canonical( const string& fname) const
{
- FILE *f = fopen( fname, "w");
+ FILE *f = fopen( fname.c_str(), "w");
if ( !f )
return -1;
- for ( size_t p = 0; p < pages(); ++p ) {
- float N = operator[](p).NREM,
+ for ( size_t p = 0; p < n_pages(); ++p ) {
+ float N = operator[](p).NREM,
R = operator[](p).REM,
W = operator[](p).Wake;
fprintf( f, "%s\n",
@@ -141,15 +145,15 @@ save_canonical( const char *fname) const
int
sigfile::CHypnogram::
-load_canonical( const char *fname,
+load_canonical( const string& fname,
const TCustomScoreCodes& custom_score_codes)
{
ifstream f (fname);
if ( !f.good() )
return -1;
- size_t p = 0;
- string token;
+ size_t p = 0;
+ string token;
while ( p < _pages.size() ) {
if ( f.eof() )
return 2; // short
diff --git a/upstream/src/libsigfile/page.hh b/upstream/src/libsigfile/page.hh
index 3aefb3a..4f1ae9c 100644
--- a/upstream/src/libsigfile/page.hh
+++ b/upstream/src/libsigfile/page.hh
@@ -10,8 +10,8 @@
*/
-#ifndef _SIGFILE_PAGE_H
-#define _SIGFILE_PAGE_H
+#ifndef SIGFILE_PAGE_H_
+#define SIGFILE_PAGE_H_
#include <vector>
@@ -29,7 +29,7 @@ namespace sigfile {
struct SPage {
- enum TScore : unsigned short {
+ enum TScore {
none,
nrem1,
nrem2,
@@ -56,14 +56,16 @@ struct SPage {
static TScore
__attribute__ ((const))
- char2score( char c)
+ char2score( const char c)
{
size_t i = TScore::none;
while ( i != TScore::TScore_total && c != score_codes[i] )
++i;
return (TScore)i;
}
- static char score2char( TScore i)
+ static char
+ __attribute__ ((const))
+ score2char( const TScore i)
{
if ( i >= TScore::TScore_total )
return '?';
@@ -74,7 +76,7 @@ struct SPage {
float NREM, REM, Wake;
TScore score() const
{
- return (NREM > 3./4) ? TScore::nrem4
+ return (NREM > 3./4) ? TScore::nrem4
:(NREM > 1./2) ? TScore::nrem3
:(REM >= 1./3) ? TScore::rem
:(Wake >= 1./3) ? TScore::wake
@@ -202,37 +204,32 @@ class CHypnogram {
}
size_t pagesize() const { return _pagesize; }
- size_t pages() const { return _pages.size(); }
- size_t length_in_seconds() const { return pages() * pagesize(); }
+ size_t n_pages() const { return _pages.size(); }
+ const vector<SPage>& pages() const { return _pages; }
+ vector<SPage>& pages() { return _pages; }
+ size_t length_in_seconds() const { return n_pages() * pagesize(); }
float percent_scored( float *nrem_p = NULL, float *rem_p = NULL, float *wake_p = NULL) const;
- enum TError : int {
+ enum TError {
ok = 0,
nofile = -1,
baddata = -2,
wrongpagesize = -3,
shortread = -4
};
- TError save( const char*) const;
- TError load( const char*);
- TError save( const string& s) const
- {
- return save(s.c_str());
- }
- TError load( const string& s)
- {
- return load(s.c_str());
- }
+ TError save( const string&) const;
+ TError load( const string&);
- int save_canonical( const char* fname) const;
+ int save_canonical( const string& fname) const;
typedef array<string, (size_t)SPage::TScore::TScore_total> TCustomScoreCodes;
- int load_canonical( const char* fname)
+ int load_canonical( const string& fname)
{
- return load_canonical( fname,
- TCustomScoreCodes {{" -0", "1", "2", "3", "4", "6Rr8", "Ww5"}});
+ return load_canonical(
+ fname,
+ TCustomScoreCodes {{" -0", "1", "2", "3", "4", "6Rr8", "Ww5"}});
}
- int load_canonical( const char* fname,
+ int load_canonical( const string& fname,
const TCustomScoreCodes&);
};
diff --git a/upstream/src/libsigfile/typed-source.cc b/upstream/src/libsigfile/typed-source.cc
index 964919f..83f0ccb 100644
--- a/upstream/src/libsigfile/typed-source.cc
+++ b/upstream/src/libsigfile/typed-source.cc
@@ -69,11 +69,11 @@ CTypedSource (const string& fname,
// CHypnogram::
CHypnogram::load( sigfile::make_fname_hypnogram(fname, pagesize));
size_t scorable_pages = ceil( _obj->recording_time() / pagesize);
- if ( CHypnogram::pages() != scorable_pages ) {
- if ( CHypnogram::pages() > 0 )
+ if ( CHypnogram::n_pages() != scorable_pages ) {
+ if ( CHypnogram::n_pages() > 0 )
fprintf( stderr, "CSource(\"%s\"): number of scorable pages @pagesize=%zu (%g / %zu = %zu) "
"differs from the number read from hypnogram file (%zu); adjusting hypnogram size\n",
- fname.c_str(), pagesize, _obj->recording_time(), pagesize, scorable_pages, CHypnogram::pages());
+ fname.c_str(), pagesize, _obj->recording_time(), pagesize, scorable_pages, CHypnogram::n_pages());
CHypnogram::_pages.resize( scorable_pages);
}
}
--
Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/aghermann.git
More information about the debian-med-commit
mailing list