Пример #1
0
 grid( const comma::command_line_options& options )
     : csv_( make_csv_options_( options ) )
     , istream_( std::cin, csv_ )
     , permissive_( options.exists( "--permissive" ) )
     , reverse_( options.exists( "--reverse" ) )
     , voxel_map_( resolution_( options.value< double >( "--resolution", 1 ) ) ) // quick and dirty: does not matter for now, but may be used in future
 {
 }
Пример #2
0
 static void run(const comma::command_line_options& options)
 {
     comma::csv::options csv(options);
     if(options.exists("--output-fields")) { std::cout<<comma::join(comma::csv::names<T>(), ',')<<std::endl; return;}
     if(options.exists("--output-format")) { std::cout<< comma::csv::format::value<T>(csv.fields,true)<<std::endl; return;}
     process(csv);
 }
Пример #3
0
int traits::run( const comma::command_line_options& options )
{
    comma::csv::options csv( options );
    csv.full_xpath = true;
    bool discard_collinear = options.exists( "--discard-collinear" );
    line_t first_default = comma::csv::ascii< line_t >().get( options.value< std::string >( "--first", "0,0,0,0,0,0" ) );
    line_t second_default = comma::csv::ascii< line_t >().get( options.value< std::string >( "--second", "0,0,0,0,0,0" ) );
    comma::csv::input_stream< lines_t > istream( std::cin, csv, std::make_pair( first_default, second_default ) );
    comma::csv::output_stream < output_t > ostream( std::cout, csv.binary(), false, csv.flush );
    comma::csv::tied< lines_t, output_t > tied( istream, ostream );
    while( istream.ready() || ( std::cin.good() && !std::cin.eof() ) )
    {
        const lines_t* r = istream.read();
        if( !r ) { break; }
        const Eigen::Vector3d& f = ( r->first.second - r->first.first ).normalized();
        const Eigen::Vector3d& s = ( r->second.second - r->second.first ).normalized();
        if( comma::math::equal( f.dot( s ), f.norm() * s.norm() ) )
        {
            if( discard_collinear ) { continue; }
            std::cerr << "points-calc: lines-nearest: got collinear lines (" << r->first.first.transpose() << " , " << r->first.second.transpose() << ") and (" << r->second.first.transpose() << " , " << r->second.second.transpose() << "), please use --discard collinear to discard" << std::endl;
            return 1;
        }
        const Eigen::Vector3d& m = s.cross( f ).normalized();
        const Eigen::Vector3d& n = s.cross( m ).normalized();
        const Eigen::Vector3d& d = r->second.first - r->first.first;
        const Eigen::Vector3d& a = r->first.first + f * n.dot( d ) / n.dot( f );
        const Eigen::Vector3d& b = a + m * m.dot( d );
        tied.append( output_t( a, b ) );
    }
    return 0;
}
Пример #4
0
std::string make_style( const comma::command_line_options& options, const std::string& what, const bool parse_colour )
{
    std::string style = options.value< std::string >( "--style", "" );
    if( options.exists( "--stroke-width" ) )
    {
        if( style.size() ) { style += ";"; }
        style += "stroke-width:" + options.value< std::string >( "--stroke-width" );
    }
    if( parse_colour && options.exists( "--colour,--color,-c" ) )
    {
        if( style.size() ) { style += ";"; }
        std::string attribute = "fill";
        if( what == "line" || what == "lines" || what == "polyline" || what == "polygon" ) { attribute = "stroke"; }
        style += attribute + ":" + options.value< std::string >( "--colour,--color,-c" );
    }
    return style;
}
Пример #5
0
 options( const comma::command_line_options& options )
     : scale( comma::csv::ascii< std::pair< double, double > >().get( options.value< std::string >( "--scale", "0,255" ) ) )
     , colourmap( options.value< std::string >( "--colour-map,--colourmap,--colour", "0,255,0" ) )
     , dial_colour( options.value< std::string >( "--dial-colour", "white" ) )
     , do_not_clean( options.exists( "--dirty,--do-not-clean" ) )
     //, offset_from_center( options.value( "--offset-from-center", 0 ) )
 {
 }
Пример #6
0
 intervals( const comma::command_line_options& options ) : options( options )
                                                         , csv( options )
                                                         , ocsv( options )
                                                         , ascii_csv( options )
                                                         , empty( traits< bound_type >::cast( options.optional< std::string >( "--empty" ) ) )
                                                         , intervals_only( options.exists( "--intervals-only" ) )
                                                         , use_limits( options.exists( "--limits,-l" ) )
 {
     if( csv.fields.empty() ) { csv.fields = comma::join( comma::csv::names< interval_t< From, To > >(), ',' ); }
     if( ocsv.fields.empty() || intervals_only )
     {
         ocsv.fields = comma::join( comma::csv::names< interval_t< From, To > >(), ',' );
         if( ocsv.binary() && intervals_only ) { ocsv.format( comma::csv::format::value< interval_t< From, To > >() ); }
     }
     ascii_csv.fields = ocsv.fields;
     ascii_csv.quote = boost::none;
     if( verbose ) { std::cerr << app_name << ": empty: "; empty ? std::cerr << *empty : std::cerr << "<none>"; std::cerr << std::endl; }
 }
Пример #7
0
void process( const comma::command_line_options& options, const std::string& output_id )
{
    typedef snark::timestamped< T > output_t;
    if( options.exists( "--list-fields,--output-fields" ) ) { std::cout << comma::join( comma::csv::names< output_t >( false ), ',' ) << std::endl; return; }
    comma::csv::options csv;
    csv.fields = options.value< std::string >( "--fields", "" );
    csv.full_xpath = false;
    if( options.exists( "--format" ) ) { std::cout << comma::csv::format::value< output_t >( csv.fields, false ) << std::endl; return; }
    if( options.exists( "--binary,-b" ) ) { csv.format( comma::csv::format::value< output_t >( csv.fields, false ) ); }
    comma::csv::ascii_input_stream< input_t > istream( std::cin, "" );
    comma::csv::output_stream< output_t > ostream( std::cout, csv );
    while( !is_shutdown && std::cin.good() && !std::cin.eof() )
    {
        const input_t* input = istream.read();
        if( !input ) { break; }
        std::string input_id = reinterpret_cast< const braille::header* >( &input->data[0] )->id();
        if( output_id != input_id )  { continue; }
        ostream.write( output_t( input->t, *reinterpret_cast< const braille::packet< P::size >* >( &input->data[0] ) ) );
    }
}
Пример #8
0
 constraints( const comma::command_line_options& options ) // quick and dirty
 {
     equals = get_optional_< T >( options, "--equals" );
     not_equal = get_optional_< T >( options, "--not-equal" );
     from = get_optional_< T >( options, "--from,--greater-or-equal,--ge" );
     to = get_optional_< T >( options, "--to,--less-or-equal,--le" );
     less = get_optional_< T >( options, "--less" );
     greater = get_optional_< T >( options, "--greater" );
     const boost::optional< std::string >& s = get_optional_< std::string >( options, "--regex" );
     if( s ) { regex = boost::regex( *s ); }
     sorted = options.exists( "--sorted,--input-sorted" );
 }
Пример #9
0
inline static void init( comma::csv::options& csv_options, const comma::command_line_options& options, const std::string& defaultFields )
{
    csv_options.full_xpath = options.exists( "--full-xpath" );
    csv_options.fields = options.value( "--fields", defaultFields );
    if( options.exists( "--binary" ) )
    {
        boost::optional< std::string > format = options.optional< std::string >( "--binary" );
        if( format )
        {
            csv_options.format( options.value< std::string >( "--binary" ) );
        }
    }
    csv_options.precision = options.value< unsigned int >( "--precision", 12 );
    csv_options.delimiter = options.exists( "--delimiter" ) ? options.value( "--delimiter", ',' ) : options.value( "-d", ',' );
    boost::optional< std::string > quote_character = options.optional< std::string >( "--quote" );
    if( quote_character )
    {
        switch( quote_character->size() )
        {
            case 0: csv_options.quote.reset(); break;
            case 1: csv_options.quote = ( *quote_character )[0]; break;
            case 2: COMMA_THROW( comma::exception, "expected a quote character, got \"" << *quote_character << "\"" );
        }
    }
    csv_options.flush = options.exists( "--flush" );
}
Пример #10
0
 intervals( const comma::command_line_options& options ) : options( options )
                                                         , csv( options )
                                                         , ocsv( options )
                                                         , ascii_csv( options )
                                                         , empty( traits< bound_type >::cast( options.optional< std::string >( "--empty" ) ) )
                                                         , intervals_only( options.exists( "--intervals-only" ) )
                                                         , use_limits( options.exists( "--limits,-l" ) )
 {
     if( csv.fields.empty() ) { csv.fields = comma::join( comma::csv::names< interval_t< From, To > >(), ',' ); }
     if( ocsv.fields.empty() || intervals_only )
     {
         ocsv.fields = comma::join( comma::csv::names< interval_t< From, To > >(), ',' );
         if( ocsv.binary() && ( intervals_only || append ) ) { ocsv.format( comma::csv::format::value< interval_t< From, To > >() ); }
     }
     ascii_csv.fields = ocsv.fields;
     ascii_csv.quote = boost::none;
     if( verbose ) { std::cerr << app_name << ": empty: "; empty ? std::cerr << *empty : std::cerr << "<none>"; std::cerr << std::endl; }
     options.assert_mutually_exclusive( "overlap-count-min,overlap-count-max", "overlap-count" );
     if( options.exists( "--overlap-count" ) )
     {
         min_overlap_count = max_overlap_count = options.value< unsigned int >( "--overlap-count" );
     }
     else
     {
         min_overlap_count = options.value( "--overlap-count-min", 0 );
         max_overlap_count = options.value( "--overlap-count-max", std::numeric_limits< unsigned int >::max() );
     }
 }
Пример #11
0
int sort( const comma::command_line_options& options )
{
    input_t::map sorted_map;
    input_t default_input;
    std::vector< std::string > v = comma::split( stdin_csv.fields, ',' );
    std::vector< std::string > order = options.exists("--order") ? comma::split( options.value< std::string >( "--order" ), ',' ) : v;
    std::vector< std::string > w (v.size());
    bool unique = options.exists("--unique,-u");
    
    std::string first_line;
    comma::csv::format f;
    if( stdin_csv.binary() ) { f = stdin_csv.format(); }
    else if( options.exists( "--format" ) ) { f = comma::csv::format( options.value< std::string >( "--format" ) ); }
    else
    {
        while( std::cin.good() && first_line.empty() ) { std::getline( std::cin, first_line ); }
        if( first_line.empty() ) { return 0; }
        f = comma::csv::impl::unstructured::guess_format( first_line, stdin_csv.delimiter );
        if( verbose ) { std::cerr << "csv-sort: guessed format: " << f.string() << std::endl; }
    }
    for( std::size_t i = 0; i < order.size(); ++i ) // quick and dirty, wasteful, but who cares
    {
        if (order[i].empty()) continue;
        for( std::size_t k = 0; k < v.size(); ++k )
        {
            if( v[k].empty() || v[k] != order[i] ) 
            { 
                if ( k + 1 == v.size()) 
                { 
                    std::cerr << "csv-sort: order field name \"" << order[i] << "\" not found in input fields \"" << stdin_csv.fields << "\"" << std::endl;
                    return 1;
                }
                continue; 
            }
            std::string type = default_input.keys.append( f.offset( k ).type );
            w[k] = "keys/" + type;
            
            ordering_t o;
            if ( type[0] == 's' ) { o.type = ordering_t::str_type; o.index = default_input.keys.strings.size() - 1; }
            else if ( type[0] == 'l' ) { o.type = ordering_t::long_type; o.index = default_input.keys.longs.size() - 1; }
            else if ( type[0] == 'd' ) { o.type = ordering_t::double_type; o.index = default_input.keys.doubles.size() - 1; }
            else if ( type[0] == 't' ) { o.type = ordering_t::time_type; o.index = default_input.keys.time.size() - 1; }
            else { std::cerr << "csv-sort: cannot sort on field " << v[k] << " of type \"" << type << "\"" << std::endl; return 1; }
            
            ordering.push_back(o);
            
            break;
        }
    }
    stdin_csv.fields = comma::join( w, ',' );
    if ( verbose ) { std::cerr << "csv-sort: fields: " << stdin_csv.fields << std::endl; }
    comma::csv::input_stream< input_t > stdin_stream( std::cin, stdin_csv, default_input );
    #ifdef WIN32
    if( stdin_stream.is_binary() ) { _setmode( _fileno( stdout ), _O_BINARY ); }
    #endif
    
    if (!first_line.empty()) 
    { 
        input_t::map::mapped_type& d = sorted_map[ comma::csv::ascii< input_t >(stdin_csv,default_input).get(first_line) ];
        d.push_back( first_line + "\n" );
    }
    
    while( stdin_stream.ready() || ( std::cin.good() && !std::cin.eof() ) )
    {
        const input_t* p = stdin_stream.read();
        if( !p ) { break; }
        if( stdin_stream.is_binary() )
        {
            input_t::map::mapped_type& d = sorted_map[ *p ];
            if (unique && !d.empty()) continue;
            d.push_back( std::string() );
            d.back().resize( stdin_csv.format().size() );
            ::memcpy( &d.back()[0], stdin_stream.binary().last(), stdin_csv.format().size() );
        }
        else
        {
            input_t::map::mapped_type& d = sorted_map[ *p ];
            if (unique && !d.empty()) continue;
            d.push_back( comma::join( stdin_stream.ascii().last(), stdin_csv.delimiter ) + "\n" );
        }
    }
    
    if( options.exists( "--reverse,-r" ) ) { output_( sorted_map.rbegin(), sorted_map.rend() ); }
    else { output_( sorted_map.begin(), sorted_map.end() ); }
    
    return 0;
}
Пример #12
0
 static int run( const comma::command_line_options& options )
 {
     if( options.exists( "--input-fields" ) ) { std::cout << comma::join( comma::csv::names< grid::input >( true ), ',' ) << std::endl; return 0; }
     grid g( options );
     return g.read_();
 }