prepare imc_channel + imc_raw for cython interface

This commit is contained in:
Mario Fink 2021-02-12 09:52:52 +01:00
parent 40a922893d
commit 3d9305a1be
2 changed files with 22 additions and 8 deletions

View File

@ -88,6 +88,9 @@ namespace imc
template<typename dt>
std::string joinvec(std::vector<dt> myvec, unsigned long int limit = 10)
{
// include entire list for limit = - 1
limit = (limit == 0) ? myvec.size() : limit;
std::stringstream ss;
ss<<"[";
if ( myvec.size() <= limit )
@ -341,7 +344,7 @@ namespace imc
}
// provide JSON string of metadata
std::string get_json()
std::string get_json(bool include_data = false)
{
std::stringstream ss;
ss<<"{"<<"\"uuid\":\""<<uuid_
@ -358,11 +361,15 @@ namespace imc
<<"\",\"xoffset\":\""<<xoffset_
<<"\",\"group\":{"<<"\"index\":\""<<group_index_
<<"\",\"name\":\""<<group_name_
<<"\",\"comment\":\""<<group_comment_<<"\""<<"}"
<<"\",\"ydata\":\""<<imc::joinvec<imc::datatype>(ydata_)
<<"\",\"xdata\":\""<<imc::joinvec<double>(xdata_)
<<"\",\"aff. blocks\":\""<<chnenv_.get_json()
<<"\"}";
<<"\",\"comment\":\""<<group_comment_<<"\""<<"}";
if ( include_data )
{
ss<<"\",\"ydata\":\""<<imc::joinvec<imc::datatype>(ydata_,0)
<<"\",\"xdata\":\""<<imc::joinvec<double>(xdata_,0);
}
// ss<<"\",\"aff. blocks\":\""<<chnenv_.get_json()
ss<<"\"}";
return ss.str();
}

View File

@ -267,14 +267,21 @@ namespace imc
}
// get list of channels with metadata
std::vector<std::string> get_channels()
std::vector<std::string> get_channels(bool json = false, bool include_data = false)
{
std::vector<std::string> chns;
for ( std::map<std::string,imc::channel>::iterator it = channels_.begin();
it != channels_.end(); ++it)
{
if ( !json )
{
chns.push_back(it->second.get_info());
}
else
{
chns.push_back(it->second.get_json(include_data));
}
}
return chns;
}