From 704220ebab532c0b8a5466bfcc83d071af0bd9db Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Thu, 4 Aug 2022 13:18:46 +0900 Subject: [PATCH 01/18] Fix comparison value type for Side type variables. --- rcss/rcg/team_graphic.cpp | 2 +- rcss/rcg/types.h | 2 +- src/player_painter.cpp | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rcss/rcg/team_graphic.cpp b/rcss/rcg/team_graphic.cpp index 4621198..a76b065 100644 --- a/rcss/rcg/team_graphic.cpp +++ b/rcss/rcg/team_graphic.cpp @@ -220,7 +220,7 @@ TeamGraphic::createFromRawXpm( const char * const * xpm_data ) std::snprintf( header, 31, "%zd %zd %zd 1", XpmTile::WIDTH, XpmTile::HEIGHT, color_set.size() ); tile->setHeader( header ); - for ( const std::string col : color_set ) + for ( const std::string & col : color_set ) { tile->addColor( col.c_str() ); } diff --git a/rcss/rcg/types.h b/rcss/rcg/types.h index f4e7bc6..0d712d7 100644 --- a/rcss/rcg/types.h +++ b/rcss/rcg/types.h @@ -1037,7 +1037,7 @@ struct PlayerT { */ bool isFocusing() const { - return focus_side_ != 'n'; + return focus_side_ != NEUTRAL; } /*! diff --git a/src/player_painter.cpp b/src/player_painter.cpp index 477cad2..8de1090 100644 --- a/src/player_painter.cpp +++ b/src/player_painter.cpp @@ -328,10 +328,10 @@ PlayerPainter::drawBody( QPainter & painter, if ( ! param.player_.hasFullEffort( param.player_type_.effort_max_ ) ) { - std::cerr << "no full effort. max=" << param.player_type_.effort_max_ - << " val=" << param.player_.effort_ - << " ptype=" << param.player_.type_ - << std::endl; + // std::cerr << "no full effort. max=" << param.player_type_.effort_max_ + // << " val=" << param.player_.effort_ + // << " ptype=" << param.player_.type_ + // << std::endl; int r = param.draw_radius_ + 2; painter.setPen( opt.effortDecayedPen() ); painter.setBrush( Qt::NoBrush ); @@ -506,7 +506,7 @@ PlayerPainter::drawCatchArea( QPainter & painter, = std::sqrt( std::pow( SP.catchable_area_w_ * 0.5, 2.0 ) + std::pow( SP.catchable_area_l_, 2.0 ) ); const int catchable = opt.scale( catchable_area ); - painter.setPen( ( param.player_.side_ == 'l' ) + painter.setPen( ( param.player_.side_ == rcss::rcg::LEFT ) ? opt.leftGoaliePen() : opt.rightGoaliePen() ); painter.setBrush( Qt::NoBrush ); @@ -524,7 +524,7 @@ PlayerPainter::drawCatchArea( QPainter & painter, const int max_r = opt.scale( max_area ); if ( max_r > catchable ) { - painter.setPen( ( param.player_.side_ == 'l' ) + painter.setPen( ( param.player_.side_ == rcss::rcg::LEFT ) ? opt.leftGoalieStretchPen() : opt.rightGoalieStretchPen() ); painter.drawEllipse( param.x_ - max_r, @@ -570,7 +570,7 @@ PlayerPainter::drawCatchArea( QPainter & painter, int text_radius = std::min( 40, param.draw_radius_ ); - painter.setPen( ( param.player_.side_ == 'l' ) + painter.setPen( ( param.player_.side_ == LEFT ) ? opt.rightGoaliePen() : opt.leftGoaliePen() ); painter.setFont( opt.playerFont() ); @@ -995,7 +995,7 @@ PlayerPainter::drawOffsideLine( QPainter & painter, for ( int i = 0; i < rcss::rcg::MAX_PLAYER*2; ++i ) { if ( show.players_[i].state_ != 0 - && show.players_[i].side_ == 'l' ) + && show.players_[i].side_ == rcss::rcg::LEFT ) { float x = show.players_[i].x_; if ( x < offside_l ) @@ -1022,7 +1022,7 @@ PlayerPainter::drawOffsideLine( QPainter & painter, for ( int i = 0; i < rcss::rcg::MAX_PLAYER*2; ++i ) { if ( show.players_[i].state_ != 0 - && show.players_[i].side_ == 'r' ) + && show.players_[i].side_ == rcss::rcg::RIGHT ) { float x = show.players_[i].x_; if ( offside_r < x ) From f8c5676a74bd793e887bb00eba479a98818c6ccc Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Sun, 19 Feb 2023 17:54:32 +0900 Subject: [PATCH 02/18] Change the version numver of JSON rcg to -1, in order to completely distinguish it from other formats. --- rcss/rcg/types.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rcss/rcg/types.h b/rcss/rcg/types.h index 0d712d7..09684cd 100644 --- a/rcss/rcg/types.h +++ b/rcss/rcg/types.h @@ -699,7 +699,8 @@ struct dispinfo_t2 { constexpr int REC_VERSION_4 = 4; //!< The version number of rcg v4, which is written at the head of the file. constexpr int REC_VERSION_5 = 5; //!< The version number of rcg v5, which is written at the head of the file. constexpr int REC_VERSION_6 = 6; //!< The version number of rcg v6, which is written at the head of the file. -constexpr int REC_VERSION_JSON = REC_VERSION_6; //!< The version number of json rcg. + +constexpr int REC_VERSION_JSON = -1; //!< The version number of json rcg, which is written at the head of the file. /*! \struct BallT From d4978a34bc8943db1c2d2e538e0d8100723b56d2 Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Sun, 19 Feb 2023 22:00:54 +0900 Subject: [PATCH 03/18] Add new parameters introduced by v18 observation model. --- rcss/rcg/types.cpp | 24 ++++++++++++++++++++++++ rcss/rcg/types.h | 24 +++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/rcss/rcg/types.cpp b/rcss/rcg/types.cpp index 887bfb8..e275fe8 100644 --- a/rcss/rcg/types.cpp +++ b/rcss/rcg/types.cpp @@ -295,6 +295,18 @@ PlayerTypeT::PlayerTypeT() double_map_.insert( DoubleMap::value_type( "kick_power_rate", &kick_power_rate_ ) ); double_map_.insert( DoubleMap::value_type( "foul_detect_probability", &foul_detect_probability_ ) ); double_map_.insert( DoubleMap::value_type( "catchable_area_l_stretch", &catchable_area_l_stretch_ ) ); + // 18.0 + double_map_.insert( DoubleMap::value_type( "unum_far_length", &unum_far_length_ ) ); + double_map_.insert( DoubleMap::value_type( "unum_too_far_length", &unum_too_far_length_ ) ); + double_map_.insert( DoubleMap::value_type( "team_far_length", &team_far_length_ ) ); + double_map_.insert( DoubleMap::value_type( "team_too_far_length", &team_too_far_length_ ) ); + double_map_.insert( DoubleMap::value_type( "player_max_observation_length", &player_max_observation_length_ ) ); + double_map_.insert( DoubleMap::value_type( "ball_vel_far_length", &ball_vel_far_length_ ) ); + double_map_.insert( DoubleMap::value_type( "ball_vel_too_far_length", &ball_vel_too_far_length_ ) ); + double_map_.insert( DoubleMap::value_type( "ball_max_observation_length", &ball_max_observation_length_ ) ); + double_map_.insert( DoubleMap::value_type( "flag_chg_far_length", &flag_chg_far_length_ ) ); + double_map_.insert( DoubleMap::value_type( "flag_chg_too_far_length", &flag_chg_too_far_length_ ) ); + double_map_.insert( DoubleMap::value_type( "flag_max_observation_length", &flag_max_observation_length_ ) ); } @@ -318,6 +330,18 @@ PlayerTypeT::toSExp( std::ostream & os ) const to_sexp( os, "kick_power_rate", quantize( kick_power_rate_, 0.000001 ) ); to_sexp( os, "foul_detect_probability", quantize( foul_detect_probability_, 0.000001 ) ); to_sexp( os, "catchable_area_l_stretch", quantize( catchable_area_l_stretch_, 0.000001 ) ); + // 18.0 + to_sexp( os, "unum_far_length", quantize( unum_far_length_, 0.000001 ) ); + to_sexp( os, "unum_too_far_length", quantize( unum_too_far_length_, 0.000001 ) ); + to_sexp( os, "team_far_length", quantize( team_far_length_, 0.000001 ) ); + to_sexp( os, "team_too_far_length", quantize( team_too_far_length_, 0.000001 ) ); + to_sexp( os, "player_max_observation_length", quantize( player_max_observation_length_, 0.000001 ) ); + to_sexp( os, "ball_vel_far_length", quantize( ball_vel_far_length_, 0.000001 ) ); + to_sexp( os, "ball_vel_too_far_length", quantize( ball_vel_too_far_length_, 0.000001 ) ); + to_sexp( os, "ball_max_observation_length", quantize( ball_max_observation_length_, 0.000001 ) ); + to_sexp( os, "flag_chg_far_length", quantize( flag_chg_far_length_, 0.000001 ) ); + to_sexp( os, "flag_chg_too_far_length", quantize( flag_chg_too_far_length_, 0.000001 ) ); + to_sexp( os, "flag_max_observation_length", quantize( flag_max_observation_length_, 0.000001 ) ); os << ')'; return os; diff --git a/rcss/rcg/types.h b/rcss/rcg/types.h index 09684cd..65fcf74 100644 --- a/rcss/rcg/types.h +++ b/rcss/rcg/types.h @@ -765,6 +765,9 @@ struct PlayerT { float view_width_; //!< view width (degree). high: value>0, low: value<0 + float focus_dist_; //!< distance to the focus point + float focus_dir_; //!< direction to the focus point, relative to head (degree) + float stamina_; //!< satamina value float effort_; //!< effort value float recovery_; //!< recovery value @@ -781,6 +784,7 @@ struct PlayerT { UInt16 tackle_count_; //!< tackle command count UInt16 pointto_count_; //!< pointto command count UInt16 attentionto_count_; //!< attentionto command count + UInt16 change_focus_count_; //!< change_focus command count /*! \brief initialize all variables @@ -816,7 +820,8 @@ struct PlayerT { say_count_( 0xFFFF ), tackle_count_( 0xFFFF ), pointto_count_( 0xFFFF ), - attentionto_count_( 0xFFFF ) + attentionto_count_( 0xFFFF ), + change_focus_count_( 0xFFFF ) { } /*! @@ -1115,6 +1120,9 @@ struct PlayerT { double viewWidth() const { return view_width_; } + double focusDist() const { return focus_dist_; } + double focusDir() const { return focus_dir_; } + double stamina() const { return stamina_; } double effort() const { return effort_; } double recovery() const { return recovery_; } @@ -1131,6 +1139,7 @@ struct PlayerT { int tackleCount() const { return tackle_count_; } int pointtoCount() const { return pointto_count_; } int attentiontoCount() const { return attentionto_count_; } + int changeFocusCount() const { return change_focus_count_; } bool hasFullEffort( const double max_effort ) const { @@ -1674,6 +1683,19 @@ struct PlayerTypeT { double foul_detect_probability_; double catchable_area_l_stretch_; + // v18 + double unum_far_length_; + double unum_too_far_length_; + double team_far_length_; + double team_too_far_length_; + double player_max_observation_length_; + double ball_vel_far_length_; + double ball_vel_too_far_length_; + double ball_max_observation_length_; + double flag_chg_far_length_; + double flag_chg_too_far_length_; + double flag_max_observation_length_; + PlayerTypeT(); /*! From de95eeea9bda4e3ac07a793d7962db6b20fc2ca3 Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Sun, 19 Feb 2023 22:12:22 +0900 Subject: [PATCH 04/18] Add the check of rcg version 6. Change the header of json format. --- rcss/rcg/parser.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/rcss/rcg/parser.cpp b/rcss/rcg/parser.cpp index e7cafa0..20e97d7 100644 --- a/rcss/rcg/parser.cpp +++ b/rcss/rcg/parser.cpp @@ -79,6 +79,17 @@ Parser::create( std::istream & is ) return ptr; } + if ( header[0] == 'J' + && header[1] == 'S' + && header[2] == 'O' + && header[3] == 'N' ) + { + std::cerr << "(rcss::rcg::Parser::create) game log version = " << version - static_cast< int >( '0' ) << " (json)" << std::endl; + ptr = Parser::Ptr( new ParserJSON() ); + return ptr; + } + + if ( header[0] == 'U' && header[1] == 'L' && header[2] == 'G' ) @@ -86,12 +97,14 @@ Parser::create( std::istream & is ) version = static_cast< int >( header[3] ); } - if ( version == static_cast< int >( '0' ) + REC_VERSION_JSON ) + if ( version == static_cast< int >( '0' ) + REC_VERSION_6 ) { - std::cerr << "(rcss::rcg::Parser::create) game log version = " << version - static_cast< int >( '0' ) << " (json)" << std::endl; - ptr = Parser::Ptr( new ParserJSON() ); + // ParserV4 can parse the v6 format. + std::cerr << "(rcss::rcg::Parser::crete) game log version = " << version - static_cast< int >( '0' ) << std::endl; + ptr = Parser::Ptr( new rcss::rcg::ParserV4() ); + } - if ( version == static_cast< int >( '0' ) + REC_VERSION_5 ) + else if ( version == static_cast< int >( '0' ) + REC_VERSION_5 ) { // ParserV4 can parse the v5 format. std::cerr << "(rcss::rcg::Parser::crete) game log version = " << version - static_cast< int >( '0' ) << std::endl; From 3e3bf9297d4a6285002082e021b93140335ec00b Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Sun, 19 Feb 2023 23:09:51 +0900 Subject: [PATCH 05/18] Add code to ParserV4 to parser focus_point information. --- rcss/rcg/parser_v4.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/rcss/rcg/parser_v4.cpp b/rcss/rcg/parser_v4.cpp index 37597ca..0835de2 100644 --- a/rcss/rcg/parser_v4.cpp +++ b/rcss/rcg/parser_v4.cpp @@ -272,7 +272,7 @@ ParserV4::parseShow( const int n_line, } // players - // ((side unum) type state x y vx vy body neck [pointx pointy] (v h 90) (s 4000 1 1)[(f side unum)]) + // ((side unum) type state x y vx vy body neck [pointx pointy] (v h 90) [(fp dist dir)] (s 4000 1 1)[(f side unum)]) // (c 1 1 1 1 1 1 1 1 1 1 1)) for ( int i = 0; i < MAX_PLAYER*2; ++i ) { @@ -322,7 +322,7 @@ ParserV4::parseShow( const int n_line, p.neck_ = strtof( buf, &next ); buf = next; while ( *buf == ' ' ) ++buf; - // x y vx vy body neck + // arm if ( *buf != '\0' && *buf != '(' ) { p.point_x_ = strtof( buf, &next ); buf = next; @@ -336,6 +336,16 @@ ParserV4::parseShow( const int n_line, p.high_quality_ = ( *buf == 'h' ? true : false ); ++buf; p.view_width_ = strtof( buf, &next ); buf = next; + // (fp dist dir) + while ( *buf == ' ' ) ++buf; + if ( ! std::strncmp( buf, "(fp ", 4 ) ) + { + buf += 4; + p.focus_dist_ = strtof( buf, &next ); buf = next; + p.focus_dir_ = strtof( buf, &next ); buf = next; + while ( *buf == ' ' || *buf == ')' ) ++buf; + } + // (s stamina effort recovery[ capacity]) while ( *buf != '\0' && *buf != 's' ) ++buf; ++buf; // skip 's' //while ( *buf != '\0' && *buf != ' ' ) ++buf; @@ -353,15 +363,13 @@ ParserV4::parseShow( const int n_line, while ( *buf != '\0' && *buf != '(' ) ++buf; // (f side unum) - if ( *(buf + 1) == 'f' ) + if ( ! std::strncmp( buf, "(f ", 3 ) ) { - while ( *buf != '\0' && *buf != ' ' ) ++buf; + buf += 3; while ( *buf == ' ' ) ++buf; p.focus_side_ = ( *buf == 'l' ? LEFT : *buf == 'r' ? RIGHT : NEUTRAL ); ++buf; p.focus_unum_ = static_cast< Int16 >( std::strtol( buf, &next, 10 ) ); buf = next; - while ( *buf == ' ' ) ++buf; - while ( *buf == ')' ) ++buf; - while ( *buf == ' ' ) ++buf; + while ( *buf == ' ' || *buf == ')' ) ++buf; } // (c kick dash turn catch move tneck cview say tackle pointto atttention) From 1a292af2a2b3bd9009b9faa9dc50b2d5c93907e3 Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Sun, 19 Feb 2023 23:32:12 +0900 Subject: [PATCH 06/18] Add focus_point handling to ParserJSON. --- rcss/rcg/parser_json.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rcss/rcg/parser_json.cpp b/rcss/rcg/parser_json.cpp index 671e666..b450431 100644 --- a/rcss/rcg/parser_json.cpp +++ b/rcss/rcg/parser_json.cpp @@ -313,6 +313,9 @@ ParserJSON::Impl::setPlayer( const nlohmann::json & player, p->view_width_ = player.at( "vw" ); + if ( player.contains( "fdist" ) ) p->focus_dist_ = player.at( "fdist" ); + if ( player.contains( "fdir" ) ) p->focus_dir_ = player.at( "fdir" ); + p->stamina_ = player.at( "stamina" ); p->effort_ = player.at( "effort" ); p->recovery_ = player.at( "recovery" ); From 881c0223fe97589ad10d28d655ad94617e2bd44c Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Sun, 19 Feb 2023 23:35:42 +0900 Subject: [PATCH 07/18] Add the command count for change_focus to ParserJSON --- rcss/rcg/parser_json.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/rcss/rcg/parser_json.cpp b/rcss/rcg/parser_json.cpp index b450431..06ca9bc 100644 --- a/rcss/rcg/parser_json.cpp +++ b/rcss/rcg/parser_json.cpp @@ -335,6 +335,7 @@ ParserJSON::Impl::setPlayer( const nlohmann::json & player, p->tackle_count_ = counts.at( "tackle" ); p->pointto_count_ = counts.at( "pointto" ); p->attentionto_count_ = counts.at( "attentionto" ); + if ( counts.contains( "change_focus" ) ) p->change_focus_count_ = counts.at( "change_focus" ); } } catch ( std::exception & e ) From b84a4443d154a7ddb2ecd76c83448ccd82443102 Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Sun, 19 Feb 2023 23:38:00 +0900 Subject: [PATCH 08/18] Add the command count for change_focus to ParserV4 --- rcss/rcg/parser_v4.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rcss/rcg/parser_v4.cpp b/rcss/rcg/parser_v4.cpp index 0835de2..700d034 100644 --- a/rcss/rcg/parser_v4.cpp +++ b/rcss/rcg/parser_v4.cpp @@ -372,7 +372,7 @@ ParserV4::parseShow( const int n_line, while ( *buf == ' ' || *buf == ')' ) ++buf; } - // (c kick dash turn catch move tneck cview say tackle pointto atttention) + // (c kick dash turn catch move tneck cview say tackle pointto atttention[ change_focus]) while ( *buf == '(' ) ++buf; ++buf; // skip 'c' //while ( *buf != '\0' && *buf != ' ' ) ++buf; p.kick_count_ = static_cast< UInt16 >( std::strtol( buf, &next, 10 ) ); buf = next; @@ -386,6 +386,10 @@ ParserV4::parseShow( const int n_line, p.tackle_count_ = static_cast< UInt16 >( std::strtol( buf, &next, 10 ) ); buf = next; p.pointto_count_ = static_cast< UInt16 >( std::strtol( buf, &next, 10 ) ); buf = next; p.attentionto_count_ = static_cast< UInt16 >( std::strtol( buf, &next, 10 ) ); buf = next; + if ( *buf != ')' ) + { + p.change_focus_count_ = static_cast< UInt16 >( std::strtol( buf, &next, 10 ) ); buf = next; + } while ( *buf == ')' ) ++buf; while ( *buf == ' ' ) ++buf; From c758c681a582baf1c9fa6169a62fc191ff76f27b Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Mon, 20 Feb 2023 00:18:07 +0900 Subject: [PATCH 09/18] Add an option and controls to determine whether focus_point information is drawn or not. --- src/config_dialog.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++ src/config_dialog.h | 3 +++ src/options.cpp | 21 ++++++++++++++++++++ src/options.h | 8 ++++++++ 4 files changed, 78 insertions(+) diff --git a/src/config_dialog.cpp b/src/config_dialog.cpp index f96094e..8dbf1c3 100644 --- a/src/config_dialog.cpp +++ b/src/config_dialog.cpp @@ -601,6 +601,20 @@ ConfigDialog::createPlayerInfoControls() this, SLOT( clickShowViewArea( bool ) ) ); layout->addWidget( M_view_area_cb ); + // + M_focus_point_cb = new QCheckBox( tr( "Focus Point" ) ); + M_focus_point_cb->setChecked( Options::instance().showFocusPoint() ); + connect( M_focus_point_cb, SIGNAL( clicked( bool ) ), + this, SLOT( clickShowFocusPoint( bool ) ) ); + layout->addWidget( M_focus_point_cb ); + + top_layout->addLayout( layout ); + } + + { + QHBoxLayout * layout = new QHBoxLayout(); + layout->setMargin( 0 ); + layout->setSpacing( 0 ); // M_catch_area_cb = new QCheckBox( tr( "Catch Area" ) ); M_catch_area_cb->setChecked( Options::instance().showCatchArea() ); @@ -1182,6 +1196,9 @@ ConfigDialog::createColorItems() M_color_list_box->addItem( new ColorItem( tr( "Large View Area" ), o->largeViewAreaPen().color(), std::bind( &Options::setLargeViewAreaColor, o, _1 ) ) ); + M_color_list_box->addItem( new ColorItem( tr( "Focus Point" ), + o->focusPointPen().color(), + std::bind( &Options::setFocusPointColor, o, _1 ) ) ); M_color_list_box->addItem( new ColorItem( tr( "Ball Collision" ), o->ballCollideBrush().color(), std::bind( &Options::setBallCollideColor, o, _1 ) ) ); @@ -1304,6 +1321,7 @@ ConfigDialog::updateAll() M_player_type_cb->setChecked( opt.showPlayerType() ); M_stamina_cb->setChecked( opt.showStamina() ); M_view_area_cb->setChecked( opt.showViewArea() ); + M_focus_point_cb->setChecked( opt.showFocusPoint() ); M_catch_area_cb->setChecked( opt.showCatchArea() ); M_tackle_area_cb->setChecked( opt.showTackleArea() ); M_kick_accel_area_cb->setChecked( opt.showKickAccelArea() ); @@ -1885,6 +1903,34 @@ ConfigDialog::toggleShowViewArea() emit configured(); } + +/*-------------------------------------------------------------------*/ +/*! + +*/ +void +ConfigDialog::clickShowFocusPoint( bool checked ) +{ + if ( Options::instance().showFocusPoint() != checked ) + { + Options::instance().toggleShowFocusPoint(); + emit configured(); + } +} + +/*-------------------------------------------------------------------*/ +/*! + +*/ +void +ConfigDialog::toggleShowFocusPoint() +{ + Options::instance().toggleShowFocusPoint(); + M_focus_point_cb->setChecked( Options::instance().showFocusPoint() ); + + emit configured(); +} + /*-------------------------------------------------------------------*/ /*! diff --git a/src/config_dialog.h b/src/config_dialog.h index 05a42c2..3b75596 100644 --- a/src/config_dialog.h +++ b/src/config_dialog.h @@ -170,6 +170,7 @@ class ConfigDialog QCheckBox * M_stamina_cb; QCheckBox * M_stamina_capacity_cb; QCheckBox * M_view_area_cb; + QCheckBox * M_focus_point_cb; QCheckBox * M_catch_area_cb; QCheckBox * M_tackle_area_cb; QCheckBox * M_kick_accel_area_cb; @@ -259,6 +260,7 @@ private slots: void clickShowStamina( bool checked ); void clickShowStaminaCapacity( bool checked ); void clickShowViewArea( bool checked ); + void clickShowFocusPoint( bool checked ); void clickShowCatchArea( bool checked ); void clickShowTackleArea( bool checked ); void clickShowKickAccelArea( bool checked ); @@ -335,6 +337,7 @@ public slots: void toggleShowStamina(); void toggleShowStaminaCapacity(); void toggleShowViewArea(); + void toggleShowFocusPoint(); void toggleShowCatchArea(); void toggleShowTackleArea(); void toggleShowKickAccelArea(); diff --git a/src/options.cpp b/src/options.cpp index 8261bdb..baae587 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -115,6 +115,7 @@ const QColor Options::PLAYER_NUMBER_INNER_COLOR( 0, 0, 0 ); const QColor Options::NECK_COLOR( 255, 0, 0 ); const QColor Options::VIEW_AREA_COLOR( 191, 239, 191 ); const QColor Options::LARGE_VIEW_AREA_COLOR( 255, 255, 255 ); +const QColor Options::FOCUS_POINT_COLOR( 255, 255, 255 ); const QColor Options::BALL_COLLIDE_COLOR( 255, 0, 0 ); const QColor Options::PLAYER_COLLIDE_COLOR( 105, 155, 235 ); const QColor Options::EFFORT_DECAYED_COLOR( 255, 0, 0 ); @@ -240,6 +241,7 @@ Options::Options() M_show_player_number( true ), M_show_player_type( false ), M_show_view_area( false ), + M_show_focus_point( false ), M_show_illegal_defense( false ), M_show_catch_area( false ), M_show_tackle_area( false ), @@ -294,6 +296,7 @@ Options::Options() M_neck_pen( NECK_COLOR, 0, Qt::SolidLine ), M_view_area_pen( VIEW_AREA_COLOR, 0, Qt::SolidLine ), M_large_view_area_pen( LARGE_VIEW_AREA_COLOR, 0, Qt::SolidLine ), + M_focus_point_pen( FOCUS_POINT_COLOR, 0, Qt::SolidLine ), M_ball_collide_brush( BALL_COLLIDE_COLOR, Qt::SolidPattern ), M_player_collide_brush( PLAYER_COLLIDE_COLOR, Qt::SolidPattern ), M_effort_decayed_pen( EFFORT_DECAYED_COLOR, 0, Qt::SolidLine ), @@ -457,6 +460,9 @@ Options::readSettings() val = settings.value( "show_view_area" ); if ( val.isValid() ) M_show_view_area = val.toBool(); + val = settings.value( "show_focus_point" ); + if ( val.isValid() ) M_show_focus_point = val.toBool(); + val = settings.value( "show_illegal_defense" ); if ( val.isValid() ) M_show_illegal_defense = val.toBool(); @@ -615,6 +621,9 @@ Options::readSettings() val = settings.value( "large_view_area_pen" ); if ( val.isValid() ) M_large_view_area_pen.setColor( val.toString() ); + val = settings.value( "focus_point_pen" ); + if ( val.isValid() ) M_focus_point_pen.setColor( val.toString() ); + val = settings.value( "ball_collide_brush" ); if ( val.isValid() ) M_ball_collide_brush.setColor( val.toString() ); @@ -738,6 +747,7 @@ Options::writeSettings( bool all ) settings.setValue( "show_player_type", M_show_player_type ); settings.setValue( "show_view_area", M_show_view_area ); settings.setValue( "show_illegal_defense", M_show_illegal_defense ); + settings.setValue( "show_focus_point", M_show_focus_point ); settings.setValue( "show_catch_area", M_show_catch_area ); settings.setValue( "show_tackle_area", M_show_tackle_area ); settings.setValue( "show_kick_accel_area", M_show_kick_accel_area ); @@ -789,6 +799,7 @@ Options::writeSettings( bool all ) settings.setValue( "neck_pen", M_neck_pen.color().name() ); settings.setValue( "view_area_pen", M_view_area_pen.color().name() ); settings.setValue( "large_view_area_pen", M_large_view_area_pen.color().name() ); + settings.setValue( "focus_point_pen", M_focus_point_pen.color().name() ); settings.setValue( "ball_collide_brush", M_ball_collide_brush.color().name() ); settings.setValue( "effort_decayed_pen", M_effort_decayed_pen.color().name() ); settings.setValue( "recovery_decayed_pen", M_recovery_decayed_pen.color().name() ); @@ -958,6 +969,11 @@ Options::parseCmdLine( int argc, "bool", to_onoff( M_show_view_area ) ); parser.addOption( opt_show_view_area ); + QCommandLineOption opt_show_focus_point( "show-focus-point", + "Show player's focus point. (Default=" + to_onoff( M_show_focus_point ) + ")", + "bool", + to_onoff( M_show_focus_point ) ); + parser.addOption( opt_show_focus_point ); QCommandLineOption opt_show_illegal_defense( "show-illegal-defense", "show player's illegal defense state. (Default=" + to_onoff( M_show_illegal_defense ) + ")", "bool", @@ -1069,6 +1085,7 @@ Options::parseCmdLine( int argc, if ( parser.isSet( opt_show_player_number ) ) M_show_player_number = to_bool( parser.value( opt_show_player_number ), M_show_player_number ); if ( parser.isSet( opt_show_player_type ) ) M_show_player_type = to_bool( parser.value( opt_show_player_type ), M_show_player_type ); if ( parser.isSet( opt_show_view_area ) ) M_show_view_area = to_bool( parser.value( opt_show_view_area ), M_show_view_area ); + if ( parser.isSet( opt_show_focus_point ) ) M_show_focus_point = to_bool( parser.value( opt_show_focus_point ), M_show_focus_point ); if ( parser.isSet( opt_show_illegal_defense ) ) M_show_illegal_defense = to_bool( parser.value( opt_show_illegal_defense ), M_show_illegal_defense ); if ( parser.isSet( opt_show_catch_area ) ) M_show_catch_area = to_bool( parser.value( opt_show_catch_area ), M_show_catch_area ); if ( parser.isSet( opt_show_tackle_area ) ) M_show_tackle_area = to_bool( parser.value( opt_show_tackle_area ), M_show_tackle_area ); @@ -1182,6 +1199,9 @@ Options::parseCmdLine( int argc, ( "show-view-area", po::value< bool >( &M_show_view_area )->default_value( M_show_view_area, to_onoff( M_show_view_area ) ), "show player\'s view area." ) + ( "show-focus-point", + po::value< bool >( &M_show_focus_point )->default_value( M_show_focus_point, to_onoff( M_show_focus_point ) ), + "show player\'s focus point." ) ( "show-illegal-defense", po::value< bool >( &M_show_illegal_defense )->default_value( M_show_illegal_defense, to_onoff( M_show_illegal_defense ) ), "show player\'s illegal defense state." ) @@ -1434,6 +1454,7 @@ Options::setDefaultColor() M_neck_pen.setColor( NECK_COLOR ); M_view_area_pen.setColor( VIEW_AREA_COLOR ); M_large_view_area_pen.setColor( LARGE_VIEW_AREA_COLOR ); + M_focus_point_pen.setColor( FOCUS_POINT_COLOR ); M_ball_collide_brush.setColor( BALL_COLLIDE_COLOR ); M_player_collide_brush.setColor( PLAYER_COLLIDE_COLOR ); M_effort_decayed_pen.setColor( EFFORT_DECAYED_COLOR ); diff --git a/src/options.h b/src/options.h index 3679ba0..bfe15fe 100644 --- a/src/options.h +++ b/src/options.h @@ -121,6 +121,7 @@ class Options { static const QColor NECK_COLOR; static const QColor VIEW_AREA_COLOR; static const QColor LARGE_VIEW_AREA_COLOR; + static const QColor FOCUS_POINT_COLOR; static const QColor BALL_COLLIDE_COLOR; static const QColor PLAYER_COLLIDE_COLOR; static const QColor EFFORT_DECAYED_COLOR; @@ -192,6 +193,7 @@ class Options { bool M_show_player_number; bool M_show_player_type; bool M_show_view_area; + bool M_show_focus_point; bool M_show_illegal_defense; bool M_show_catch_area; bool M_show_tackle_area; @@ -265,6 +267,7 @@ class Options { QPen M_neck_pen; QPen M_view_area_pen; QPen M_large_view_area_pen; + QPen M_focus_point_pen; QBrush M_ball_collide_brush; QBrush M_player_collide_brush; QPen M_effort_decayed_pen; @@ -393,6 +396,9 @@ class Options { bool showViewArea() const { return M_show_view_area; } void toggleShowViewArea() { M_show_view_area = ! M_show_view_area; } + bool showFocusPoint() const { return M_show_focus_point; } + void toggleShowFocusPoint() { M_show_focus_point = ! M_show_focus_point; } + bool showIllegalDefense() const { return M_show_illegal_defense; } void toggleShowIllegalDefense() { M_show_illegal_defense = ! M_show_illegal_defense; } @@ -619,6 +625,8 @@ class Options { void setViewAreaColor( const QColor & col ) { M_view_area_pen.setColor( col ); } const QPen & largeViewAreaPen() const { return M_large_view_area_pen; } void setLargeViewAreaColor( const QColor & col ) { M_large_view_area_pen.setColor( col ); } + const QPen & focusPointPen() const { return M_focus_point_pen; } + void setFocusPointColor( const QColor & col ) { M_focus_point_pen.setColor( col ); } const QBrush & ballCollideBrush() const { return M_ball_collide_brush; } void setBallCollideColor( const QColor & col ) { M_ball_collide_brush.setColor( col ); } const QBrush & playerCollideBrush() const { return M_player_collide_brush; } From 47c5592d0fa0dd788ba4a63f37bd59d33284260d Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Mon, 20 Feb 2023 00:29:55 +0900 Subject: [PATCH 10/18] Add drawFocusPoint to PlayerPainter. --- src/player_painter.cpp | 44 +++++++++++++++++++++++++++++++++++++++--- src/player_painter.h | 2 ++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/player_painter.cpp b/src/player_painter.cpp index 8de1090..998c29b 100644 --- a/src/player_painter.cpp +++ b/src/player_painter.cpp @@ -155,10 +155,19 @@ PlayerPainter::drawAll( QPainter & painter, drawDir( painter, param ); if ( player.hasNeck() - && player.hasView() - && opt.showViewArea() ) + && player.hasView() ) { - drawViewArea( painter, param ); + if ( opt.showViewArea() ) + { + drawViewArea( painter, param ); + } + + if ( opt.showFocusPoint() + && player.focusDist() > 1.0e-5 + && opt.selectedPlayer( player.side(), player.unum_ ) ) + { + drawFocusPoint( painter, param ); + } } if ( player.isGoalie() @@ -484,6 +493,35 @@ PlayerPainter::drawViewArea( QPainter & painter, } } +/*-------------------------------------------------------------------*/ +/*! + + */ +void +PlayerPainter::drawFocusPoint( QPainter & painter, + const PlayerPainter::Param & param ) const +{ + const Options & opt = Options::instance(); + + const AngleDeg focus_angle = param.player_.body_ + param.player_.neck_ + param.player_.focus_dir_; + const Vector2D focus_point = Vector2D::from_polar( param.player_.focusDist(), focus_angle ); + + const int ix = opt.screenX( param.player_.x() + focus_point.x ); + const int iy = opt.screenY( param.player_.y() + focus_point.y ); + + painter.setPen( opt.focusPointPen()); + painter.setBrush( Qt::NoBrush ); + painter.drawEllipse( ix - param.draw_radius_ / 2, + iy - param.draw_radius_ / 2, + param.draw_radius_ , + param.draw_radius_ ); + painter.drawEllipse( ix - param.draw_radius_, + iy - param.draw_radius_, + param.draw_radius_ * 2, + param.draw_radius_ * 2 ); + +} + /*-------------------------------------------------------------------*/ /*! diff --git a/src/player_painter.h b/src/player_painter.h index c37e2c9..63eaffe 100644 --- a/src/player_painter.h +++ b/src/player_painter.h @@ -97,6 +97,8 @@ class PlayerPainter const PlayerPainter::Param & param ) const; void drawViewArea( QPainter & painter, const PlayerPainter::Param & param ) const; + void drawFocusPoint( QPainter & painter, + const PlayerPainter::Param & param ) const; void drawCatchArea( QPainter & painter, const PlayerPainter::Param & param ) const; void drawTackleArea( QPainter & painter, From 7d1705e35b94b03e66e284a371cb111244dc9280 Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Mon, 20 Feb 2023 01:01:48 +0900 Subject: [PATCH 11/18] Suppor new protocol version 5 and -1(json) --- src/monitor_client.cpp | 21 ++++++++++++--------- src/options.cpp | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/monitor_client.cpp b/src/monitor_client.cpp index f4bcf5b..ef7dcd6 100644 --- a/src/monitor_client.cpp +++ b/src/monitor_client.cpp @@ -70,15 +70,18 @@ MonitorClient::MonitorClient( QObject * parent, { assert( parent ); - // check protocl versin range - if ( version < 1 ) + // check protocol versin range + if ( version == -1 ) + { + M_version = -1; + } + else if ( version < 1 ) { M_version = 1; } - - if ( 5 < version ) + else if ( 5 < version ) { - M_version = 4; + M_version = 5; } QHostInfo host = QHostInfo::fromName( QString::fromLatin1( hostname ) ); @@ -166,7 +169,7 @@ MonitorClient::handleReceive() { int receive_count = 0; - if ( M_version >= 5 ) + if ( M_version == -1 ) // JSON { char buf[8192]; while ( M_socket->hasPendingDatagrams() ) @@ -198,7 +201,7 @@ MonitorClient::handleReceive() ++receive_count; } } - else if ( M_version >= 3 ) + else if ( M_version >= 3 ) // S-Expression { char buf[8192]; while ( M_socket->hasPendingDatagrams() ) @@ -230,7 +233,7 @@ MonitorClient::handleReceive() ++receive_count; } } - else if ( M_version == 2 ) + else if ( M_version == 2 ) // binary format v2 { rcss::rcg::dispinfo_t2 disp2; while ( M_socket->hasPendingDatagrams() ) @@ -263,7 +266,7 @@ MonitorClient::handleReceive() ++receive_count; } } - else if ( M_version == 1 ) + else if ( M_version == 1 ) // binary format v1 { rcss::rcg::dispinfo_t disp1; while ( M_socket->hasPendingDatagrams() ) diff --git a/src/options.cpp b/src/options.cpp index baae587..9b69855 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -211,7 +211,7 @@ Options::Options() M_connect( true ), M_server_host( "127.0.0.1" ), M_server_port( 6000 ), - M_client_version( 4 ), + M_client_version( 5 ), M_auto_quit_mode( false ), M_auto_quit_wait( 5 ), M_auto_reconnect_mode( false ), From 5c75582db7d963a21ec448c650a7d934ff35e526 Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Mon, 20 Feb 2023 01:02:15 +0900 Subject: [PATCH 12/18] Fix a console message. --- rcss/rcg/parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rcss/rcg/parser.cpp b/rcss/rcg/parser.cpp index 20e97d7..6ed5ca3 100644 --- a/rcss/rcg/parser.cpp +++ b/rcss/rcg/parser.cpp @@ -84,7 +84,7 @@ Parser::create( std::istream & is ) && header[2] == 'O' && header[3] == 'N' ) { - std::cerr << "(rcss::rcg::Parser::create) game log version = " << version - static_cast< int >( '0' ) << " (json)" << std::endl; + std::cerr << "(rcss::rcg::Parser::create) game log version = json" << std::endl; ptr = Parser::Ptr( new ParserJSON() ); return ptr; } From 42321fe970080b10f756e699bf5625f14eb0e5ed Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Mon, 20 Feb 2023 01:44:30 +0900 Subject: [PATCH 13/18] Add null pointer check for the rcg parser creation. --- src/main_window.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main_window.cpp b/src/main_window.cpp index 40939aa..b108071 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -1454,7 +1454,8 @@ MainWindow::openGameLogFileImpl( const QString & filepath ) timer.start(); rcss::rcg::Parser::Ptr parser = rcss::rcg::Parser::create( fin ); - if ( ! parser->parse( fin, handler ) ) + if ( ! parser + || ! parser->parse( fin, handler ) ) { return false; } From adfb22e15c4f505431f031eb1ec0f15e56e6f704 Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Mon, 20 Feb 2023 01:45:00 +0900 Subject: [PATCH 14/18] Fix the version check in rcg::ParserV4. --- rcss/rcg/parser.cpp | 7 +++---- rcss/rcg/parser_v4.cpp | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rcss/rcg/parser.cpp b/rcss/rcg/parser.cpp index 6ed5ca3..bd9a438 100644 --- a/rcss/rcg/parser.cpp +++ b/rcss/rcg/parser.cpp @@ -100,19 +100,18 @@ Parser::create( std::istream & is ) if ( version == static_cast< int >( '0' ) + REC_VERSION_6 ) { // ParserV4 can parse the v6 format. - std::cerr << "(rcss::rcg::Parser::crete) game log version = " << version - static_cast< int >( '0' ) << std::endl; + std::cerr << "(rcss::rcg::Parser::crete) game log version = " << REC_VERSION_6 << std::endl; ptr = Parser::Ptr( new rcss::rcg::ParserV4() ); - } else if ( version == static_cast< int >( '0' ) + REC_VERSION_5 ) { // ParserV4 can parse the v5 format. - std::cerr << "(rcss::rcg::Parser::crete) game log version = " << version - static_cast< int >( '0' ) << std::endl; + std::cerr << "(rcss::rcg::Parser::crete) game log version = " << REC_VERSION_5 << std::endl; ptr = Parser::Ptr( new rcss::rcg::ParserV4() ); } else if ( version == static_cast< int >( '0' ) + REC_VERSION_4 ) { - std::cerr << "(rcss::rcg::Parser::create) game log version = " << version - static_cast< int >( '0' ) << std::endl; + std::cerr << "(rcss::rcg::Parser::create) game log version = " << REC_VERSION_4 << std::endl; ptr = Parser::Ptr( new rcss::rcg::ParserV4() ); } else if ( version == REC_VERSION_3 ) diff --git a/rcss/rcg/parser_v4.cpp b/rcss/rcg/parser_v4.cpp index 700d034..06ac13d 100644 --- a/rcss/rcg/parser_v4.cpp +++ b/rcss/rcg/parser_v4.cpp @@ -76,7 +76,8 @@ ParserV4::parse( std::istream & is, const int version = std::stoi( line.substr( 3 ) ); if ( version != REC_VERSION_4 - && version != REC_VERSION_5 ) + && version != REC_VERSION_5 + && version != REC_VERSION_6 ) { return false; } @@ -335,9 +336,9 @@ ParserV4::parseShow( const int n_line, while ( *buf == ' ' ) ++buf; p.high_quality_ = ( *buf == 'h' ? true : false ); ++buf; p.view_width_ = strtof( buf, &next ); buf = next; + while ( *buf == ' ' || *buf == ')' ) ++buf; // (fp dist dir) - while ( *buf == ' ' ) ++buf; if ( ! std::strncmp( buf, "(fp ", 4 ) ) { buf += 4; From 92cd0a19c49751e7994db120928c19ed3654d642 Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Mon, 20 Feb 2023 22:42:39 +0900 Subject: [PATCH 15/18] Change the drawn shapes for the focus point information. --- src/player_painter.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/player_painter.cpp b/src/player_painter.cpp index 998c29b..5f44bab 100644 --- a/src/player_painter.cpp +++ b/src/player_painter.cpp @@ -511,10 +511,7 @@ PlayerPainter::drawFocusPoint( QPainter & painter, painter.setPen( opt.focusPointPen()); painter.setBrush( Qt::NoBrush ); - painter.drawEllipse( ix - param.draw_radius_ / 2, - iy - param.draw_radius_ / 2, - param.draw_radius_ , - param.draw_radius_ ); + painter.drawLine( param.x_, param.y_, ix, iy ); painter.drawEllipse( ix - param.draw_radius_, iy - param.draw_radius_, param.draw_radius_ * 2, From 9cb50c513bc7a424e22410408376ee92619aa0a9 Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Mon, 6 Mar 2023 18:24:28 +0900 Subject: [PATCH 16/18] Add an option to control the radius of focus point drawing, and UI to configure it. --- src/config_dialog.cpp | 33 ++++++++++++++++++++++++++++++--- src/config_dialog.h | 2 ++ src/options.cpp | 19 +++++++++++++++++++ src/options.h | 8 ++++++++ src/player_painter.cpp | 9 +++++---- 5 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/config_dialog.cpp b/src/config_dialog.cpp index 8dbf1c3..4f97007 100644 --- a/src/config_dialog.cpp +++ b/src/config_dialog.cpp @@ -439,7 +439,7 @@ ConfigDialog::createObjectSizeControls() QHBoxLayout * box = new QHBoxLayout(); // - box->addWidget( new QLabel( tr( "Ball Size:" ) ) ); + box->addWidget( new QLabel( tr( "Ball:" ) ) ); // M_ball_size_text = new QLineEdit( tr( "0.35" ) ); M_ball_size_text->setValidator( new QDoubleValidator( 0.01, 100.0, 3, M_ball_size_text ) ); @@ -448,15 +448,24 @@ ConfigDialog::createObjectSizeControls() this, SLOT( editBallSize( const QString & ) ) ); box->addWidget( M_ball_size_text ); // - box->addWidget( new QLabel( tr( " Player Size:" ) ) ); + box->addWidget( new QLabel( tr( " Player:" ) ) ); // M_player_size_text = new QLineEdit( tr( "0.0" ) ); - M_player_size_text->setValidator( new QDoubleValidator( 0.0, 100.0, 3, M_ball_size_text ) ); + M_player_size_text->setValidator( new QDoubleValidator( 0.0, 100.0, 3, M_player_size_text ) ); M_player_size_text->setMaximumSize( 48, 24 ); connect( M_player_size_text, SIGNAL( textChanged( const QString & ) ), this, SLOT( editPlayerSize( const QString & ) ) ); box->addWidget( M_player_size_text ); // + box->addWidget( new QLabel( tr( " Focus Point:" ) ) ); + // + M_focus_point_size_text = new QLineEdit( tr( "2.0" ) ); + M_focus_point_size_text->setValidator( new QDoubleValidator( 0.1, 100.0, 3, M_focus_point_size_text ) ); + M_focus_point_size_text->setMaximumSize( 48, 24 ); + connect( M_focus_point_size_text, SIGNAL( textChanged( const QString & ) ), + this, SLOT( editFocusPointSize( const QString & ) ) ); + box->addWidget( M_focus_point_size_text ); + // top_layout->addLayout( box ); group_box->setLayout( top_layout ); @@ -1491,6 +1500,24 @@ ConfigDialog::editPlayerSize( const QString & text ) /*-------------------------------------------------------------------*/ /*! +*/ +void +ConfigDialog::editFocusPointSize( const QString & text ) +{ + bool ok = true; + double value = text.toDouble( &ok ); + + if ( ok ) + { + Options::instance().setFocusPointSize( value ); + + emit configured(); + } +} + +/*-------------------------------------------------------------------*/ +/*! + */ void ConfigDialog::slideFieldScale( int value ) diff --git a/src/config_dialog.h b/src/config_dialog.h index 3b75596..4417ad3 100644 --- a/src/config_dialog.h +++ b/src/config_dialog.h @@ -146,6 +146,7 @@ class ConfigDialog // object size QLineEdit * M_ball_size_text; QLineEdit * M_player_size_text; + QLineEdit * M_focus_point_size_text; // canvas size control QLineEdit * M_canvas_width_text; @@ -350,6 +351,7 @@ public slots: void editBallSize( const QString & text ); void editPlayerSize( const QString & text ); + void editFocusPointSize( const QString & text ); void toggleFocusBall(); void toggleFocusPlayer(); diff --git a/src/options.cpp b/src/options.cpp index 9b69855..9d1a981 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -252,6 +252,7 @@ Options::Options() M_show_draw_info( true ), M_ball_size( 0.35 ), M_player_size( 0.0 ), + M_focus_point_size( 2.0 ), M_grid_step( 0.0 ), M_show_grid_coord( false ), M_team_graphic_scale( 1.0 ), @@ -510,6 +511,9 @@ Options::readSettings() val = settings.value( "player_size", M_player_size ); if ( val.isValid() ) M_player_size = val.toDouble(); + val = settings.value( "focus_point_size", M_focus_point_size ); + if ( val.isValid() ) M_focus_point_size = val.toDouble(); + val = settings.value( "team_graphic_scale", M_team_graphic_scale ); if ( val.isValid() ) M_team_graphic_scale = val.toDouble(); @@ -766,6 +770,7 @@ Options::writeSettings( bool all ) settings.beginGroup( "Size" ); settings.setValue( "ball_size", M_ball_size ); settings.setValue( "player_size", M_player_size ); + settings.setValue( "focus_point_size", M_focus_point_size ); settings.setValue( "team_graphic_scale", M_team_graphic_scale ); settings.endGroup(); @@ -1024,6 +1029,11 @@ Options::parseCmdLine( int argc, "double", to_string( M_player_size ) ); parser.addOption( opt_player_size ); + QCommandLineOption opt_focus_point_size( "focus-point-size", + "Set the fixed focus point radius. (Default=" + to_string( M_focus_point_size ) + ")", + "double", + to_string( M_focus_point_size ) ); + parser.addOption( opt_focus_point_size ); QCommandLineOption opt_show_grid_coord( "show-grid-coord", "Show coordinates values of grid lines. (Default=" + to_onoff( M_show_grid_coord ) + ")", "bool", @@ -1096,6 +1106,7 @@ Options::parseCmdLine( int argc, if ( parser.isSet( opt_show_card ) ) M_show_card = to_bool( parser.value( opt_show_card ), M_show_card ); if ( parser.isSet( opt_ball_size ) ) M_ball_size = parser.value( opt_ball_size ).toDouble(); if ( parser.isSet( opt_player_size ) ) M_player_size = parser.value( opt_player_size ).toDouble(); + if ( parser.isSet( opt_focus_point_size ) ) M_focus_point_size = parser.value( opt_focus_point_size ).toDouble(); if ( parser.isSet( opt_show_grid_coord ) ) M_show_grid_coord = to_bool( parser.value( opt_show_grid_coord ), M_show_grid_coord ); if ( parser.isSet( opt_grid_step ) ) M_grid_step = parser.value( opt_grid_step ).toDouble(); if ( parser.isSet( opt_show_flag ) ) M_show_flag = to_bool( parser.value( opt_show_flag ), M_show_flag ); @@ -1232,6 +1243,9 @@ Options::parseCmdLine( int argc, ( "player-size", po::value< double >( &M_player_size )->default_value( M_player_size, to_string( M_player_size ) ), "set a fixed player radius." ) + ( "focus-point-size", + po::value< double >( &M_focus_point_size )->default_value( M_focus_point_size, to_string( M_focus_point_size ) ), + "set a fixed focus point radius." ) ( "show-grid-coord", po::value< bool >( &M_show_grid_coord )->default_value( M_show_grid_coord, to_onoff( M_show_grid_coord ) ), "show coordinates value of grid lines." ) @@ -1409,6 +1423,11 @@ Options::checkConsistensy() M_player_size = 0.0; } + if ( M_focus_point_size < 0.1 ) + { + M_focus_point_size = 0.1; + } + if ( M_grid_step < 0.0 ) { M_grid_step = 0.0; diff --git a/src/options.h b/src/options.h index bfe15fe..2d06d57 100644 --- a/src/options.h +++ b/src/options.h @@ -208,6 +208,7 @@ class Options { double M_ball_size; //!< fixed ball radius double M_player_size; //!< fixed player radius + double M_focus_point_size; //!< fixed focus point radius double M_grid_step; bool M_show_grid_coord; @@ -443,6 +444,13 @@ class Options { M_player_size = value; } + double focusPointSize() const { return M_focus_point_size; } + void setFocusPointSize( const double value ) + { + if ( value < 0.1 ) return; + M_focus_point_size = value; + } + const double & gridStep() const { return M_grid_step; } void setGridStep( const double & value ) { M_grid_step = value; } diff --git a/src/player_painter.cpp b/src/player_painter.cpp index 5f44bab..65ac875 100644 --- a/src/player_painter.cpp +++ b/src/player_painter.cpp @@ -508,14 +508,15 @@ PlayerPainter::drawFocusPoint( QPainter & painter, const int ix = opt.screenX( param.player_.x() + focus_point.x ); const int iy = opt.screenY( param.player_.y() + focus_point.y ); + const int r = opt.scale( opt.focusPointSize() ); painter.setPen( opt.focusPointPen()); painter.setBrush( Qt::NoBrush ); painter.drawLine( param.x_, param.y_, ix, iy ); - painter.drawEllipse( ix - param.draw_radius_, - iy - param.draw_radius_, - param.draw_radius_ * 2, - param.draw_radius_ * 2 ); + painter.drawEllipse( ix - r, + iy - r, + r * 2, + r * 2 ); } From 6934c1ae72ac5f6b70caa317f65048119a22b8af Mon Sep 17 00:00:00 2001 From: Hidehisa Akiyama Date: Wed, 8 Mar 2023 13:41:01 +0900 Subject: [PATCH 17/18] Update nlohmann json and update the shared object version. --- rcss/rcg/CMakeLists.txt | 4 +- rcss/rcg/nlohmann/json.hpp | 5393 ++++++++++++++++++++++++++---------- 2 files changed, 3973 insertions(+), 1424 deletions(-) diff --git a/rcss/rcg/CMakeLists.txt b/rcss/rcg/CMakeLists.txt index 5736ca1..10a8ee2 100644 --- a/rcss/rcg/CMakeLists.txt +++ b/rcss/rcg/CMakeLists.txt @@ -28,8 +28,8 @@ target_compile_options(rcssrcg set_target_properties(rcssrcg PROPERTIES - VERSION 17.0.0 - SOVERSION 17 + VERSION 18.0.0 + SOVERSION 18 ) install(TARGETS rcssrcg LIBRARY diff --git a/rcss/rcg/nlohmann/json.hpp b/rcss/rcg/nlohmann/json.hpp index cb27e05..2448bf2 100644 --- a/rcss/rcg/nlohmann/json.hpp +++ b/rcss/rcg/nlohmann/json.hpp @@ -1,31 +1,10 @@ -/* - __ _____ _____ _____ - __| | __| | | | JSON for Modern C++ -| | |__ | | | | | | version 3.10.5 -|_____|_____|_____|_|___| https://github.com/nlohmann/json - -Licensed under the MIT License . -SPDX-License-Identifier: MIT -Copyright (c) 2013-2022 Niels Lohmann . - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT /****************************************************************************\ * Note on documentation: The source files contain links to the online * @@ -33,16 +12,12 @@ SOFTWARE. * contains the most recent documentation and should also be applicable to * * previous versions; documentation for deprecated functions is not * * removed, but marked deprecated. See "Generate documentation" section in * - * file doc/README.md. * + * file docs/README.md. * \****************************************************************************/ #ifndef INCLUDE_NLOHMANN_JSON_HPP_ #define INCLUDE_NLOHMANN_JSON_HPP_ -#define NLOHMANN_JSON_VERSION_MAJOR 3 -#define NLOHMANN_JSON_VERSION_MINOR 10 -#define NLOHMANN_JSON_VERSION_PATCH 5 - #include // all_of, find, for_each #include // nullptr_t, ptrdiff_t, size_t #include // hash, less @@ -52,18 +27,134 @@ SOFTWARE. #endif // JSON_NO_IO #include // random_access_iterator_tag #include // unique_ptr -#include // accumulate #include // string, stoi, to_string #include // declval, forward, move, pair, swap #include // vector // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + -#include #include +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// This file contains all macro definitions affecting or depending on the ABI + +#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK + #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) + #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 2 + #warning "Already included a different version of the library!" + #endif + #endif +#endif + +#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_PATCH 2 // NOLINT(modernize-macro-to-enum) + +#ifndef JSON_DIAGNOSTICS + #define JSON_DIAGNOSTICS 0 +#endif + +#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0 +#endif + +#if JSON_DIAGNOSTICS + #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag +#else + #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS +#endif + +#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp +#else + #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON +#endif + +#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION + #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0 +#endif + +// Construct the namespace ABI tags component +#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b +#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \ + NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) + +#define NLOHMANN_JSON_ABI_TAGS \ + NLOHMANN_JSON_ABI_TAGS_CONCAT( \ + NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ + NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) + +// Construct the namespace version component +#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \ + _v ## major ## _ ## minor ## _ ## patch +#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) + +#if NLOHMANN_JSON_NAMESPACE_NO_VERSION +#define NLOHMANN_JSON_NAMESPACE_VERSION +#else +#define NLOHMANN_JSON_NAMESPACE_VERSION \ + NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ + NLOHMANN_JSON_VERSION_MINOR, \ + NLOHMANN_JSON_VERSION_PATCH) +#endif + +// Combine namespace components +#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b +#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \ + NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) + +#ifndef NLOHMANN_JSON_NAMESPACE +#define NLOHMANN_JSON_NAMESPACE \ + nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) +#endif + +#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN +#define NLOHMANN_JSON_NAMESPACE_BEGIN \ + namespace nlohmann \ + { \ + inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ + NLOHMANN_JSON_ABI_TAGS, \ + NLOHMANN_JSON_NAMESPACE_VERSION) \ + { +#endif + +#ifndef NLOHMANN_JSON_NAMESPACE_END +#define NLOHMANN_JSON_NAMESPACE_END \ + } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ + } // namespace nlohmann +#endif + // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + #include // transform @@ -79,14 +170,34 @@ SOFTWARE. #include // valarray // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + +#include // nullptr_t #include // exception +#if JSON_DIAGNOSTICS + #include // accumulate +#endif #include // runtime_error #include // to_string #include // vector // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + #include // array @@ -94,102 +205,130 @@ SOFTWARE. #include // uint8_t #include // string -namespace nlohmann -{ +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // declval, pair +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { -/////////////////////////// -// JSON type enumeration // -/////////////////////////// -/*! -@brief the JSON type enumeration +template struct make_void +{ + using type = void; +}; +template using void_t = typename make_void::type; -This enumeration collects the different JSON types. It is internally used to -distinguish the stored values, and the functions @ref basic_json::is_null(), -@ref basic_json::is_object(), @ref basic_json::is_array(), -@ref basic_json::is_string(), @ref basic_json::is_boolean(), -@ref basic_json::is_number() (with @ref basic_json::is_number_integer(), -@ref basic_json::is_number_unsigned(), and @ref basic_json::is_number_float()), -@ref basic_json::is_discarded(), @ref basic_json::is_primitive(), and -@ref basic_json::is_structured() rely on it. +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END -@note There are three enumeration entries (number_integer, number_unsigned, and -number_float), because the library distinguishes these three types for numbers: -@ref basic_json::number_unsigned_t is used for unsigned integers, -@ref basic_json::number_integer_t is used for signed integers, and -@ref basic_json::number_float_t is used for floating-point numbers or to -approximate integers which do not fit in the limits of their respective type. -@sa see @ref basic_json::basic_json(const value_t value_type) -- create a JSON -value with the default value for a given type +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ -@since version 1.0.0 -*/ -enum class value_t : std::uint8_t +// https://en.cppreference.com/w/cpp/experimental/is_detected +struct nonesuch { - null, ///< null value - object, ///< object (unordered set of name/value pairs) - array, ///< array (ordered collection of values) - string, ///< string value - boolean, ///< boolean value - number_integer, ///< number value (signed integer) - number_unsigned, ///< number value (unsigned integer) - number_float, ///< number value (floating-point) - binary, ///< binary array (ordered collection of bytes) - discarded ///< discarded by the parser callback function + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const&) = delete; + nonesuch(nonesuch const&&) = delete; + void operator=(nonesuch const&) = delete; + void operator=(nonesuch&&) = delete; }; -/*! -@brief comparison operator for JSON types - -Returns an ordering that is similar to Python: -- order: null < boolean < number < object < array < string < binary -- furthermore, each type is not smaller than itself -- discarded values are not comparable -- binary is represented as a b"" string in python and directly comparable to a - string; however, making a binary array directly comparable with a string would - be surprising behavior in a JSON file. +template class Op, + class... Args> +struct detector +{ + using value_t = std::false_type; + using type = Default; +}; -@since version 1.0.0 -*/ -inline bool operator<(const value_t lhs, const value_t rhs) noexcept +template class Op, class... Args> +struct detector>, Op, Args...> { - static constexpr std::array order = {{ - 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, - 1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */, - 6 /* binary */ - } - }; + using value_t = std::true_type; + using type = Op; +}; - const auto l_index = static_cast(lhs); - const auto r_index = static_cast(rhs); - return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index]; -} -} // namespace detail -} // namespace nlohmann +template class Op, class... Args> +using is_detected = typename detector::value_t; -// #include +template class Op, class... Args> +struct is_detected_lazy : is_detected { }; +template class Op, class... Args> +using detected_t = typename detector::type; -#include -// #include +template class Op, class... Args> +using detected_or = detector; + +template class Op, class... Args> +using detected_or_t = typename detected_or::type; +template class Op, class... Args> +using is_detected_exact = std::is_same>; + +template class Op, class... Args> +using is_detected_convertible = + std::is_convertible, To>; + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END -#include // declval, pair // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-FileCopyrightText: 2016-2021 Evan Nemerson +// SPDX-License-Identifier: MIT + /* Hedley - https://nemequ.github.io/hedley * Created by Evan Nemerson - * - * To the extent possible under law, the author(s) have dedicated all - * copyright and related and neighboring rights to this software to - * the public domain worldwide. This software is distributed without - * any warranty. - * - * For details, see . - * SPDX-License-Identifier: CC0-1.0 */ #if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15) @@ -2223,116 +2362,48 @@ JSON_HEDLEY_DIAGNOSTIC_POP #endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */ -// #include - -#include - -// #include +// This file contains all internal macro definitions (except those affecting ABI) +// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them +// #include -namespace nlohmann -{ -namespace detail -{ -template struct make_void -{ - using type = void; -}; -template using void_t = typename make_void::type; -} // namespace detail -} // namespace nlohmann +// exclude unsupported compilers +#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) + #if defined(__clang__) + #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 + #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) + #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 + #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #endif +#endif -// https://en.cppreference.com/w/cpp/experimental/is_detected -namespace nlohmann -{ -namespace detail -{ -struct nonesuch -{ - nonesuch() = delete; - ~nonesuch() = delete; - nonesuch(nonesuch const&) = delete; - nonesuch(nonesuch const&&) = delete; - void operator=(nonesuch const&) = delete; - void operator=(nonesuch&&) = delete; -}; +// C++ language standard detection +// if the user manually specified the used c++ version this is skipped +#if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11) + #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) + #define JSON_HAS_CPP_20 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 + #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 + #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) + #define JSON_HAS_CPP_14 + #endif + // the cpp 11 flag is always specified because it is the minimal required version + #define JSON_HAS_CPP_11 +#endif -template class Op, - class... Args> -struct detector -{ - using value_t = std::false_type; - using type = Default; -}; - -template class Op, class... Args> -struct detector>, Op, Args...> -{ - using value_t = std::true_type; - using type = Op; -}; - -template class Op, class... Args> -using is_detected = typename detector::value_t; - -template class Op, class... Args> -struct is_detected_lazy : is_detected { }; - -template class Op, class... Args> -using detected_t = typename detector::type; - -template class Op, class... Args> -using detected_or = detector; - -template class Op, class... Args> -using detected_or_t = typename detected_or::type; - -template class Op, class... Args> -using is_detected_exact = std::is_same>; - -template class Op, class... Args> -using is_detected_convertible = - std::is_convertible, To>; -} // namespace detail -} // namespace nlohmann - - -// This file contains all internal macro definitions -// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them - -// exclude unsupported compilers -#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) - #if defined(__clang__) - #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 - #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" - #endif - #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) - #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 - #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" - #endif - #endif -#endif - -// C++ language standard detection -// if the user manually specified the used c++ version this is skipped -#if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11) - #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) - #define JSON_HAS_CPP_20 - #define JSON_HAS_CPP_17 - #define JSON_HAS_CPP_14 - #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 - #define JSON_HAS_CPP_17 - #define JSON_HAS_CPP_14 - #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) - #define JSON_HAS_CPP_14 - #endif - // the cpp 11 flag is always specified because it is the minimal required version - #define JSON_HAS_CPP_11 -#endif +#ifdef __has_include + #if __has_include() + #include + #endif +#endif #if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM) #ifdef JSON_HAS_CPP_17 @@ -2367,7 +2438,7 @@ using is_detected_convertible = #endif // no filesystem support before MSVC 19.14: https://en.cppreference.com/w/cpp/compiler_support - #if defined(_MSC_VER) && _MSC_VER < 1940 + #if defined(_MSC_VER) && _MSC_VER < 1914 #undef JSON_HAS_FILESYSTEM #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #endif @@ -2394,6 +2465,38 @@ using is_detected_convertible = #define JSON_HAS_FILESYSTEM 0 #endif +#ifndef JSON_HAS_THREE_WAY_COMPARISON + #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \ + && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L + #define JSON_HAS_THREE_WAY_COMPARISON 1 + #else + #define JSON_HAS_THREE_WAY_COMPARISON 0 + #endif +#endif + +#ifndef JSON_HAS_RANGES + // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has syntax error + #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427 + #define JSON_HAS_RANGES 0 + #elif defined(__cpp_lib_ranges) + #define JSON_HAS_RANGES 1 + #else + #define JSON_HAS_RANGES 0 + #endif +#endif + +#ifdef JSON_HAS_CPP_17 + #define JSON_INLINE_VARIABLE inline +#else + #define JSON_INLINE_VARIABLE +#endif + +#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address) + #define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]] +#else + #define JSON_NO_UNIQUE_ADDRESS +#endif + // disable documentation warnings on clang #if defined(__clang__) #pragma clang diagnostic push @@ -2489,12 +2592,13 @@ using is_detected_convertible = class NumberUnsignedType, class NumberFloatType, \ template class AllocatorType, \ template class JSONSerializer, \ - class BinaryType> + class BinaryType, \ + class CustomBaseClass> #define NLOHMANN_BASIC_JSON_TPL \ basic_json + AllocatorType, JSONSerializer, BinaryType, CustomBaseClass> // Macros to simplify conversion from/to types @@ -2631,6 +2735,7 @@ using is_detected_convertible = #define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1; #define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1); +#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1); /*! @brief macro @@ -2641,6 +2746,10 @@ using is_detected_convertible = friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \ + friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } + /*! @brief macro @def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE @@ -2650,6 +2759,10 @@ using is_detected_convertible = inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \ + inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } + // inspired from https://stackoverflow.com/a/26745591 // allows to call any std function as if (e.g. with begin): @@ -2699,13 +2812,132 @@ using is_detected_convertible = #define JSON_EXPLICIT explicit #endif -#ifndef JSON_DIAGNOSTICS - #define JSON_DIAGNOSTICS 0 +#ifndef JSON_DISABLE_ENUM_SERIALIZATION + #define JSON_DISABLE_ENUM_SERIALIZATION 0 +#endif + +#ifndef JSON_USE_GLOBAL_UDLS + #define JSON_USE_GLOBAL_UDLS 1 +#endif + +#if JSON_HAS_THREE_WAY_COMPARISON + #include // partial_ordering +#endif + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +/////////////////////////// +// JSON type enumeration // +/////////////////////////// + +/*! +@brief the JSON type enumeration + +This enumeration collects the different JSON types. It is internally used to +distinguish the stored values, and the functions @ref basic_json::is_null(), +@ref basic_json::is_object(), @ref basic_json::is_array(), +@ref basic_json::is_string(), @ref basic_json::is_boolean(), +@ref basic_json::is_number() (with @ref basic_json::is_number_integer(), +@ref basic_json::is_number_unsigned(), and @ref basic_json::is_number_float()), +@ref basic_json::is_discarded(), @ref basic_json::is_primitive(), and +@ref basic_json::is_structured() rely on it. + +@note There are three enumeration entries (number_integer, number_unsigned, and +number_float), because the library distinguishes these three types for numbers: +@ref basic_json::number_unsigned_t is used for unsigned integers, +@ref basic_json::number_integer_t is used for signed integers, and +@ref basic_json::number_float_t is used for floating-point numbers or to +approximate integers which do not fit in the limits of their respective type. + +@sa see @ref basic_json::basic_json(const value_t value_type) -- create a JSON +value with the default value for a given type + +@since version 1.0.0 +*/ +enum class value_t : std::uint8_t +{ + null, ///< null value + object, ///< object (unordered set of name/value pairs) + array, ///< array (ordered collection of values) + string, ///< string value + boolean, ///< boolean value + number_integer, ///< number value (signed integer) + number_unsigned, ///< number value (unsigned integer) + number_float, ///< number value (floating-point) + binary, ///< binary array (ordered collection of bytes) + discarded ///< discarded by the parser callback function +}; + +/*! +@brief comparison operator for JSON types + +Returns an ordering that is similar to Python: +- order: null < boolean < number < object < array < string < binary +- furthermore, each type is not smaller than itself +- discarded values are not comparable +- binary is represented as a b"" string in python and directly comparable to a + string; however, making a binary array directly comparable with a string would + be surprising behavior in a JSON file. + +@since version 1.0.0 +*/ +#if JSON_HAS_THREE_WAY_COMPARISON + inline std::partial_ordering operator<=>(const value_t lhs, const value_t rhs) noexcept // *NOPAD* +#else + inline bool operator<(const value_t lhs, const value_t rhs) noexcept #endif +{ + static constexpr std::array order = {{ + 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, + 1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */, + 6 /* binary */ + } + }; + const auto l_index = static_cast(lhs); + const auto r_index = static_cast(rhs); +#if JSON_HAS_THREE_WAY_COMPARISON + if (l_index < order.size() && r_index < order.size()) + { + return order[l_index] <=> order[r_index]; // *NOPAD* + } + return std::partial_ordering::unordered; +#else + return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index]; +#endif +} -namespace nlohmann +// GCC selects the built-in operator< over an operator rewritten from +// a user-defined spaceship operator +// Clang, MSVC, and ICC select the rewritten candidate +// (see GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105200) +#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__) +inline bool operator<(const value_t lhs, const value_t rhs) noexcept { + return std::is_lt(lhs <=> rhs); // *NOPAD* +} +#endif + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { @@ -2722,12 +2954,13 @@ enforced with an assertion.** @since version 2.0.0 */ -inline void replace_substring(std::string& s, const std::string& f, - const std::string& t) +template +inline void replace_substring(StringType& s, const StringType& f, + const StringType& t) { JSON_ASSERT(!f.empty()); for (auto pos = s.find(f); // find first occurrence of f - pos != std::string::npos; // make sure f was found + pos != StringType::npos; // make sure f was found s.replace(pos, f.size(), t), // replace with t, and pos = s.find(f, pos + t.size())) // find next occurrence of f {} @@ -2740,10 +2973,11 @@ inline void replace_substring(std::string& s, const std::string& f, * * Note the order of escaping "~" to "~0" and "/" to "~1" is important. */ -inline std::string escape(std::string s) +template +inline StringType escape(StringType s) { - replace_substring(s, "~", "~0"); - replace_substring(s, "/", "~1"); + replace_substring(s, StringType{"~"}, StringType{"~0"}); + replace_substring(s, StringType{"/"}, StringType{"~1"}); return s; } @@ -2754,24 +2988,36 @@ inline std::string escape(std::string s) * * Note the order of escaping "~1" to "/" and "~0" to "~" is important. */ -static void unescape(std::string& s) +template +static void unescape(StringType& s) { - replace_substring(s, "~1", "/"); - replace_substring(s, "~0", "~"); + replace_substring(s, StringType{"~1"}, StringType{"/"}); + replace_substring(s, StringType{"~0"}, StringType{"~"}); } -} // namespace detail -} // namespace nlohmann +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + #include // size_t -namespace nlohmann -{ +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { + /// struct to capture the start position of the current token struct position_t { @@ -2789,270 +3035,51 @@ struct position_t } }; -} // namespace detail -} // namespace nlohmann +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END // #include +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-FileCopyrightText: 2018 The Abseil Authors +// SPDX-License-Identifier: MIT -namespace nlohmann -{ + + +#include // array +#include // size_t +#include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type +#include // index_sequence, make_index_sequence, index_sequence_for + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { -//////////////// -// exceptions // -//////////////// -/// @brief general exception of the @ref basic_json class -/// @sa https://json.nlohmann.me/api/basic_json/exception/ -class exception : public std::exception -{ - public: - /// returns the explanatory string - const char* what() const noexcept override - { - return m.what(); - } +template +using uncvref_t = typename std::remove_cv::type>::type; - /// the id of the exception - const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) +#ifdef JSON_HAS_CPP_14 - protected: - JSON_HEDLEY_NON_NULL(3) - exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} // NOLINT(bugprone-throw-keyword-missing) +// the following utilities are natively available in C++14 +using std::enable_if_t; +using std::index_sequence; +using std::make_index_sequence; +using std::index_sequence_for; - static std::string name(const std::string& ename, int id_) - { - return "[json.exception." + ename + "." + std::to_string(id_) + "] "; - } +#else - template - static std::string diagnostics(const BasicJsonType& leaf_element) - { -#if JSON_DIAGNOSTICS - std::vector tokens; - for (const auto* current = &leaf_element; current->m_parent != nullptr; current = current->m_parent) - { - switch (current->m_parent->type()) - { - case value_t::array: - { - for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i) - { - if (¤t->m_parent->m_value.array->operator[](i) == current) - { - tokens.emplace_back(std::to_string(i)); - break; - } - } - break; - } - - case value_t::object: - { - for (const auto& element : *current->m_parent->m_value.object) - { - if (&element.second == current) - { - tokens.emplace_back(element.first.c_str()); - break; - } - } - break; - } - - case value_t::null: // LCOV_EXCL_LINE - case value_t::string: // LCOV_EXCL_LINE - case value_t::boolean: // LCOV_EXCL_LINE - case value_t::number_integer: // LCOV_EXCL_LINE - case value_t::number_unsigned: // LCOV_EXCL_LINE - case value_t::number_float: // LCOV_EXCL_LINE - case value_t::binary: // LCOV_EXCL_LINE - case value_t::discarded: // LCOV_EXCL_LINE - default: // LCOV_EXCL_LINE - break; // LCOV_EXCL_LINE - } - } - - if (tokens.empty()) - { - return ""; - } - - return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, - [](const std::string & a, const std::string & b) - { - return a + "/" + detail::escape(b); - }) + ") "; -#else - static_cast(leaf_element); - return ""; -#endif - } - - private: - /// an exception object as storage for error messages - std::runtime_error m; -}; - -/// @brief exception indicating a parse error -/// @sa https://json.nlohmann.me/api/basic_json/parse_error/ -class parse_error : public exception -{ - public: - /*! - @brief create a parse error exception - @param[in] id_ the id of the exception - @param[in] pos the position where the error occurred (or with - chars_read_total=0 if the position cannot be - determined) - @param[in] what_arg the explanatory string - @return parse_error object - */ - template - static parse_error create(int id_, const position_t& pos, const std::string& what_arg, const BasicJsonType& context) - { - std::string w = exception::name("parse_error", id_) + "parse error" + - position_string(pos) + ": " + exception::diagnostics(context) + what_arg; - return {id_, pos.chars_read_total, w.c_str()}; - } - - template - static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, const BasicJsonType& context) - { - std::string w = exception::name("parse_error", id_) + "parse error" + - (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") + - ": " + exception::diagnostics(context) + what_arg; - return {id_, byte_, w.c_str()}; - } - - /*! - @brief byte index of the parse error - - The byte index of the last read character in the input file. - - @note For an input with n bytes, 1 is the index of the first character and - n+1 is the index of the terminating null byte or the end of file. - This also holds true when reading a byte vector (CBOR or MessagePack). - */ - const std::size_t byte; - - private: - parse_error(int id_, std::size_t byte_, const char* what_arg) - : exception(id_, what_arg), byte(byte_) {} - - static std::string position_string(const position_t& pos) - { - return " at line " + std::to_string(pos.lines_read + 1) + - ", column " + std::to_string(pos.chars_read_current_line); - } -}; - -/// @brief exception indicating errors with iterators -/// @sa https://json.nlohmann.me/api/basic_json/invalid_iterator/ -class invalid_iterator : public exception -{ - public: - template - static invalid_iterator create(int id_, const std::string& what_arg, const BasicJsonType& context) - { - std::string w = exception::name("invalid_iterator", id_) + exception::diagnostics(context) + what_arg; - return {id_, w.c_str()}; - } - - private: - JSON_HEDLEY_NON_NULL(3) - invalid_iterator(int id_, const char* what_arg) - : exception(id_, what_arg) {} -}; - -/// @brief exception indicating executing a member function with a wrong type -/// @sa https://json.nlohmann.me/api/basic_json/type_error/ -class type_error : public exception -{ - public: - template - static type_error create(int id_, const std::string& what_arg, const BasicJsonType& context) - { - std::string w = exception::name("type_error", id_) + exception::diagnostics(context) + what_arg; - return {id_, w.c_str()}; - } - - private: - JSON_HEDLEY_NON_NULL(3) - type_error(int id_, const char* what_arg) : exception(id_, what_arg) {} -}; - -/// @brief exception indicating access out of the defined range -/// @sa https://json.nlohmann.me/api/basic_json/out_of_range/ -class out_of_range : public exception -{ - public: - template - static out_of_range create(int id_, const std::string& what_arg, const BasicJsonType& context) - { - std::string w = exception::name("out_of_range", id_) + exception::diagnostics(context) + what_arg; - return {id_, w.c_str()}; - } - - private: - JSON_HEDLEY_NON_NULL(3) - out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {} -}; - -/// @brief exception indicating other library errors -/// @sa https://json.nlohmann.me/api/basic_json/other_error/ -class other_error : public exception -{ - public: - template - static other_error create(int id_, const std::string& what_arg, const BasicJsonType& context) - { - std::string w = exception::name("other_error", id_) + exception::diagnostics(context) + what_arg; - return {id_, w.c_str()}; - } - - private: - JSON_HEDLEY_NON_NULL(3) - other_error(int id_, const char* what_arg) : exception(id_, what_arg) {} -}; - -} // namespace detail -} // namespace nlohmann - -// #include - -// #include - - -#include // size_t -#include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type -#include // index_sequence, make_index_sequence, index_sequence_for - -// #include - - -namespace nlohmann -{ -namespace detail -{ - -template -using uncvref_t = typename std::remove_cv::type>::type; - -#ifdef JSON_HAS_CPP_14 - -// the following utilities are natively available in C++14 -using std::enable_if_t; -using std::index_sequence; -using std::make_index_sequence; -using std::index_sequence_for; - -#else - -// alias templates to reduce boilerplate -template -using enable_if_t = typename std::enable_if::type; +// alias templates to reduce boilerplate +template +using enable_if_t = typename std::enable_if::type; // The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h // which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0. @@ -3170,28 +3197,32 @@ template<> struct priority_tag<0> {}; template struct static_const { - static constexpr T value{}; + static JSON_INLINE_VARIABLE constexpr T value{}; }; -template -constexpr T static_const::value; // NOLINT(readability-redundant-declaration) - -} // namespace detail -} // namespace nlohmann - -// #include - +#ifndef JSON_HAS_CPP_17 + template + constexpr T static_const::value; +#endif -namespace nlohmann -{ -namespace detail +template +inline constexpr std::array make_array(Args&& ... args) { -// dispatching helper struct -template struct identity_tag {}; + return std::array {{static_cast(std::forward(args))...}}; +} + } // namespace detail -} // namespace nlohmann +NLOHMANN_JSON_NAMESPACE_END // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + #include // numeric_limits @@ -3199,23 +3230,30 @@ template struct identity_tag {}; #include // declval #include // tuple -// #include - - // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + #include // random_access_iterator_tag +// #include + // #include // #include -namespace nlohmann -{ +NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { + template struct iterator_types {}; @@ -3254,104 +3292,136 @@ struct iterator_traits::value>> using pointer = T*; using reference = T&; }; -} // namespace detail -} // namespace nlohmann + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + // #include -namespace nlohmann -{ +NLOHMANN_JSON_NAMESPACE_BEGIN + NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin); -} // namespace nlohmann + +NLOHMANN_JSON_NAMESPACE_END // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + // #include -namespace nlohmann -{ +NLOHMANN_JSON_NAMESPACE_BEGIN + NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end); -} // namespace nlohmann + +NLOHMANN_JSON_NAMESPACE_END // #include // #include // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.2 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ -#define INCLUDE_NLOHMANN_JSON_FWD_HPP_ + #define INCLUDE_NLOHMANN_JSON_FWD_HPP_ -#include // int64_t, uint64_t -#include // map -#include // allocator -#include // string -#include // vector + #include // int64_t, uint64_t + #include // map + #include // allocator + #include // string + #include // vector -/*! -@brief namespace for Niels Lohmann -@see https://github.com/nlohmann -@since version 1.0.0 -*/ -namespace nlohmann -{ -/*! -@brief default JSONSerializer template argument + // #include -This serializer ignores the template arguments and uses ADL -([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) -for serialization. -*/ -template -struct adl_serializer; - -/// a class to store JSON values -/// @sa https://json.nlohmann.me/api/basic_json/ -template class ObjectType = - std::map, - template class ArrayType = std::vector, - class StringType = std::string, class BooleanType = bool, - class NumberIntegerType = std::int64_t, - class NumberUnsignedType = std::uint64_t, - class NumberFloatType = double, - template class AllocatorType = std::allocator, - template class JSONSerializer = - adl_serializer, - class BinaryType = std::vector> -class basic_json; -/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document -/// @sa https://json.nlohmann.me/api/json_pointer/ -template -class json_pointer; + /*! + @brief namespace for Niels Lohmann + @see https://github.com/nlohmann + @since version 1.0.0 + */ + NLOHMANN_JSON_NAMESPACE_BEGIN -/*! -@brief default specialization -@sa https://json.nlohmann.me/api/json/ -*/ -using json = basic_json<>; + /*! + @brief default JSONSerializer template argument + + This serializer ignores the template arguments and uses ADL + ([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) + for serialization. + */ + template + struct adl_serializer; + + /// a class to store JSON values + /// @sa https://json.nlohmann.me/api/basic_json/ + template class ObjectType = + std::map, + template class ArrayType = std::vector, + class StringType = std::string, class BooleanType = bool, + class NumberIntegerType = std::int64_t, + class NumberUnsignedType = std::uint64_t, + class NumberFloatType = double, + template class AllocatorType = std::allocator, + template class JSONSerializer = + adl_serializer, + class BinaryType = std::vector, // cppcheck-suppress syntaxError + class CustomBaseClass = void> + class basic_json; + + /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document + /// @sa https://json.nlohmann.me/api/json_pointer/ + template + class json_pointer; -/// @brief a minimal map-like container that preserves insertion order -/// @sa https://json.nlohmann.me/api/ordered_map/ -template -struct ordered_map; + /*! + @brief default specialization + @sa https://json.nlohmann.me/api/json/ + */ + using json = basic_json<>; -/// @brief specialization that maintains the insertion order of object keys -/// @sa https://json.nlohmann.me/api/ordered_json/ -using ordered_json = basic_json; + /// @brief a minimal map-like container that preserves insertion order + /// @sa https://json.nlohmann.me/api/ordered_map/ + template + struct ordered_map; -} // namespace nlohmann + /// @brief specialization that maintains the insertion order of object keys + /// @sa https://json.nlohmann.me/api/ordered_json/ + using ordered_json = basic_json; + + NLOHMANN_JSON_NAMESPACE_END #endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_ -namespace nlohmann -{ +NLOHMANN_JSON_NAMESPACE_BEGIN /*! @brief detail namespace with internal helper functions @@ -3362,6 +3432,7 @@ implementations of some @ref basic_json methods, and meta-programming helpers. */ namespace detail { + ///////////// // helpers // ///////////// @@ -3380,6 +3451,16 @@ template struct is_basic_json : std::false_type {}; NLOHMANN_BASIC_JSON_TPL_DECLARATION struct is_basic_json : std::true_type {}; +// used by exceptions create() member functions +// true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t +// false_type otherwise +template +struct is_basic_json_context : + std::integral_constant < bool, + is_basic_json::type>::type>::value + || std::is_same::value > +{}; + ////////////////////// // json_ref helpers // ////////////////////// @@ -3481,6 +3562,24 @@ struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> T>::value; }; +template +using detect_key_compare = typename T::key_compare; + +template +struct has_key_compare : std::integral_constant::value> {}; + +// obtains the actual object key comparator +template +struct actual_object_comparator +{ + using object_t = typename BasicJsonType::object_t; + using object_comparator_t = typename BasicJsonType::default_object_comparator_t; + using type = typename std::conditional < has_key_compare::value, + typename object_t::key_compare, object_comparator_t>::type; +}; + +template +using actual_object_comparator_t = typename actual_object_comparator::type; /////////////////// // is_ functions // @@ -3488,10 +3587,10 @@ struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> // https://en.cppreference.com/w/cpp/types/conjunction template struct conjunction : std::true_type { }; -template struct conjunction : B1 { }; -template -struct conjunction -: std::conditional, B1>::type {}; +template struct conjunction : B { }; +template +struct conjunction +: std::conditional(B::value), conjunction, B>::type {}; // https://en.cppreference.com/w/cpp/types/negation template struct negation : std::integral_constant < bool, !B::value > { }; @@ -3655,9 +3754,18 @@ struct is_compatible_string_type template struct is_constructible_string_type { + // launder type through decltype() to fix compilation failure on ICPC +#ifdef __INTEL_COMPILER + using laundered_type = decltype(std::declval()); +#else + using laundered_type = ConstructibleStringType; +#endif + static constexpr auto value = - is_constructible::value; + conjunction < + is_constructible, + is_detected_exact>::value; }; template @@ -3775,6 +3883,81 @@ struct is_constructible_tuple : std::false_type {}; template struct is_constructible_tuple> : conjunction...> {}; +template +struct is_json_iterator_of : std::false_type {}; + +template +struct is_json_iterator_of : std::true_type {}; + +template +struct is_json_iterator_of : std::true_type +{}; + +// checks if a given type T is a template specialization of Primary +template