void printDevices( const ListDevice& devs ) { for( ListDevice::const_iterator i=devs.begin(); i!=devs.end(); i++ ) { cout << i->id << "," << i->comm << "," << i->refcount << "," << i->info << endl; } }
ListDevice getActiveDevices( const ListDevice& devs ) { ListDevice active; for( ListDevice::const_iterator i=devs.begin(); i!=devs.end(); i++ ) { if( i->refcount > 0 ) active.push_back( *i ); } return active; }
void prettyPrintDevices( const ListDevice& devs ) { const char* fmt = "%-10s %-10s %s\n"; printf( fmt, "Reference", "CommPort", "Description" ); printf( "---------- ---------- ----------------------------------------\n" ); for( ListDevice::const_iterator i=devs.begin(); i!=devs.end(); i++ ) { String comm = i->comm; if( i->refcount == 0 ) { char buf[256]; int n = snprintf( buf, 255, " (%s)", i->comm.c_str() ); comm = String( buf, buf+n ); } printf( fmt, i->id.c_str(), comm.c_str(), i->info.c_str() ); } }