@@ -327,9 +327,10 @@ void chart_store::parse_elem() {
327327 tempnote->notetype = SUB;
328328 }
329329 else {
330- char errnote[64 ];
330+ char errnote[64 ],lln[ 64 ] ;
331331 sprintf_s (errnote, " %d" , tempnote->id );
332- throw std::logic_error (" Read notes error: Invalid note type at note #" + string (errnote));
332+ sprintf_s (lln, " %d." , lines);
333+ throw std::logic_error (" Read notes error: Invalid note type at note #" + string (errnote)+" .\n Please check line " +string (lln));
333334
334335 }
335336 }
@@ -386,14 +387,15 @@ void chart_store::parse_elem() {
386387 }
387388 else if (t_buf[buf_index] == ' <' ) {
388389 if (t_buf[buf_index + 1 ] == ' /' ) {
389- // xml tag end :</...>
390+ // xml tag close :</...>
390391
391392 // scan
392393
393394 int buf_scan = buf_index + 2 ;// scan after "</"
394395 int pos_scan = buf_scan;
396+ int end_tag_line = lines;// the position of tag close
395397
396- // scan for end tag
398+ // scan for tag close
397399 if (isalpha (t_buf[buf_scan]) || t_buf[buf_scan] == ' _' ) {
398400 buf_scan++;
399401 while (isalnum (t_buf[buf_scan]) || t_buf[buf_scan] == ' _' ||
@@ -421,7 +423,7 @@ void chart_store::parse_elem() {
421423 if (t_buf[buf_index] != ' >' ) {
422424 // get error position
423425 char lln[64 ];
424- sprintf_s (lln, " %d." , lines );
426+ sprintf_s (lln, " %d." , end_tag_line );
425427
426428 throw std::logic_error (" expected \' >\' at line " + string (lln));
427429 return ;
@@ -462,19 +464,92 @@ void chart_store::parse_elem() {
462464 }
463465 else if (tag == " CMapNoteAsset" ) {// end of a note
464466 if (note_reading) {
465- int temp_id;// note id(temporary)
467+ char lln[64 ],id_string[64 ];
468+ int temp_id = tempnote->id ;// note id(temporary)
469+ // checking note info integrity
470+ // id
471+ if (temp_id == -1 ) {
472+
473+ sprintf_s (lln, " %d" , tag_line);
474+
475+ throw std::logic_error (" Error: Note without id.\n The note begins at line " + string (lln) + " in the XML." );
476+ }
477+ else {
478+ // note type
479+ if (tempnote->notetype == types::NULLTP) {
480+ sprintf_s (lln, " %d" , tag_line);
481+ sprintf_s (id_string, " %d" , temp_id);
482+ throw std::logic_error (" Error: Note #" +string (id_string)+" type not specified.\n The note begins at line " + string (lln) + " in the XML." );
483+ }
484+ // note position
485+ if (tempnote->position < -1e7 ) {
486+ sprintf_s (lln, " %d" , tag_line);
487+ sprintf_s (id_string, " %d" , temp_id);
488+
489+ throw std::logic_error (" Error: Note #" + string (id_string) + " position not specified.\n The note begins at line " + string (lln) + " in the XML." );
490+ }
491+ // note width
492+ if (tempnote->width < -1e7 ) {
493+ sprintf_s (lln, " %d" , tag_line);
494+ sprintf_s (id_string, " %d" , temp_id);
495+
496+ throw std::logic_error (" Error: Note #" + string (id_string) + " width not specified.\n The note begins at line " + string (lln) + " in the XML." );
497+ }
498+ // note time
499+ if (tempnote->time < -1e7 ) {
500+ sprintf_s (lln, " %d" , tag_line);
501+ sprintf_s (id_string, " %d" , temp_id);
502+
503+ throw std::logic_error (" Error: Note #" + string (id_string) + " time not specified.\n The note begins at line " + string (lln) + " in the XML." );
504+ }
505+ // sub id
506+ if (tempnote->subid == INT_MIN) {
507+ sprintf_s (lln, " %d" , tag_line);
508+ sprintf_s (id_string, " %d" , temp_id);
509+
510+ throw std::logic_error (" Error: Note #" + string (id_string) + " subId not specified.\n The note begins at line " + string (lln) + " in the XML." );
511+ }
512+ }
513+ // note info is complete
466514 switch (modes) {
467515 case 1 :
468- temp_id = tempnote->id ;
469- m_notes.insert (make_pair (temp_id, *tempnote));
516+ // scan for duplicated note id
517+ if (m_notes.find (temp_id) == m_notes.end ()) {
518+ m_notes.insert (make_pair (temp_id, *tempnote));
519+ }
520+ // duplicated
521+ else {
522+ sprintf_s (lln, " %d" , tag_line);
523+ sprintf_s (id_string, " %d" , temp_id);
524+
525+ throw std::logic_error (" Error: Duplicated note id: " +string (id_string)+" .\n The note begins at line " + string (lln) + " in the XML." );
526+ }
470527 break ;
471528 case 2 :
472- temp_id = tempnote->id ;
473- m_left.insert (make_pair (temp_id, *tempnote));
529+ // scan for duplicated note id
530+ if (m_left.find (temp_id) == m_left.end ()) {
531+ m_left.insert (make_pair (temp_id, *tempnote));
532+ }
533+ // duplicated
534+ else {
535+ sprintf_s (lln, " %d" , tag_line);
536+ sprintf_s (id_string, " %d" , temp_id);
537+
538+ throw std::logic_error (" Error: Duplicated note id: " + string (id_string) + " .\n The note begins at line " + string (lln) + " in the XML." );
539+ }
474540 break ;
475541 case 3 :
476- temp_id = tempnote->id ;
477- m_right.insert (make_pair (temp_id, *tempnote));
542+ // scan for duplicated note id
543+ if (m_right.find (temp_id) == m_right.end ()) {
544+ m_right.insert (make_pair (temp_id, *tempnote));
545+ }
546+ // duplicated
547+ else {
548+ sprintf_s (lln, " %d" , tag_line);
549+ sprintf_s (id_string, " %d" , temp_id);
550+
551+ throw std::logic_error (" Error: Duplicated note id: " + string (id_string) + " .\n The note begins at line " + string (lln) + " in the XML." );
552+ }
478553 break ;
479554 default :
480555 delete tempnote;
0 commit comments