// file: $isip/doc/examples/class/mmedia/mmedia_example_06/example.cc // // isip include files // #include #include // this example demonstrates how to use the AnnotationIndex object // int main(int argc, const char** argv) { // declare AnnotationIndex objects // String ancr_name_00(L"Anchor1"); String ancr_name_01(L"Anchor2"); String ancr_name_02(L"Anchor3"); String ancr_name_03(L"Anchor4"); String anno_name_00(L"Annotation1"); String anno_name_01(L"Annotation2"); // declare some units // String unit_00(L"seconds"); // declare some types // String type_00(L"type1"); String type_01(L"type2"); // declare some offsets // float offset_00 = 2.409875; float offset_01 = 2.649875; float offset_02 = 2.769875; float offset_03 = 3.273875; // declate some feature value pairs // String feat_00(L"feature1"); String feat_01(L"feature2"); String value_00(L"value1"); String value_01(L"value2"); // declare some anchors // Anchor ancr_00(ancr_name_00, offset_00, unit_00); Anchor ancr_01(ancr_name_01, offset_01, unit_00); Anchor ancr_02(ancr_name_02, offset_02, unit_00); Anchor ancr_03(ancr_name_03, offset_03, unit_00); // declare some annotations // Annotation anno_00(anno_name_00, &ancr_00, &ancr_01, type_00); Annotation anno_01(anno_name_01, &ancr_02, &ancr_03, type_01); // declare some annotation indices // AnnotationIndex andx_00; // add annotation to the annotation index // if (!andx_00.add(&anno_00)) { Console::put(L"invalid annotation index\n"); } // verify that the annotation/anchors has been added // if (!andx_00.existsAnnotation(anno_name_00)) { Console::put(L"invalid annotation index\n"); } if (andx_00.existsAnnotation(anno_name_01)) { Console::put(L"invalid annotation index\n"); } if (!andx_00.existsAnchor(ancr_name_00)) { Console::put(L"invalid annotation index\n"); } if (!andx_00.existsAnchor(ancr_name_01)) { Console::put(L"invalid annotation index\n"); } if (andx_00.existsAnchor(ancr_name_02)) { Console::put(L"invalid annotation index\n"); } if (andx_00.existsAnchor(ancr_name_03)) { Console::put(L"invalid annotation index\n"); } // add the annotation to the annotation index // if (!andx_00.add(&anno_01)) { Console::put(L"invalid annotation index\n"); } // verify that the annotation/anchor has been added // if (!andx_00.existsAnnotation(anno_name_00)) { Console::put(L"invalid annotation index\n"); } if (!andx_00.existsAnnotation(anno_name_01)) { Console::put(L"invalid annotation index\n"); } if (!andx_00.existsAnchor(ancr_name_00)) { Console::put(L"invalid annotation index\n"); } if (!andx_00.existsAnchor(ancr_name_01)) { Console::put(L"invalid annotation index\n"); } if (!andx_00.existsAnchor(ancr_name_02)) { Console::put(L"invalid annotation index\n"); } if (!andx_00.existsAnchor(ancr_name_03)) { Console::put(L"invalid annotation index\n"); } // delete annotation form the annotation index // if (!andx_00.deleteAnnotation(&anno_00)) { Console::put(L"invalid annotation index\n"); } // verify that annotation/anchors have been added to the annotation index // if (andx_00.existsAnnotation(anno_name_00)) { Console::put(L"invalid annotation index\n"); } if (!andx_00.existsAnnotation(anno_name_01)) { Console::put(L"invalid annotation index\n"); } if (!andx_00.existsAnchor(ancr_name_00)) { Console::put(L"invalid annotation index\n"); } if (!andx_00.existsAnchor(ancr_name_01)) { Console::put(L"invalid annotation index\n"); } if (!andx_00.existsAnchor(ancr_name_02)) { Console::put(L"invalid annotation index\n"); } if (!andx_00.existsAnchor(ancr_name_03)) { Console::put(L"invalid annotation index\n"); } // verify the nearest offsets // if (!Integral::almostEqual(andx_00.getNearestOffset(offset_00), offset_00)) { Console::put(L"invalid annotation index\n"); } if (!Integral::almostEqual(andx_00.getNearestOffset(offset_01), offset_01)) { Console::put(L"invalid annotation index\n"); } if (!Integral::almostEqual(andx_00.getNearestOffset(offset_02), offset_02)) { Console::put(L"invalid annotation index\n"); } if (!Integral::almostEqual(andx_00.getNearestOffset(offset_03), offset_03)) { Console::put(L"invalid annotation index\n"); } if (!Integral::almostEqual(andx_00.getNearestOffset(2.39), offset_00)) { Console::put(L"invalid annotation index\n"); } if (!Integral::almostEqual(andx_00.getNearestOffset(2.41), offset_00)) { Console::put(L"invalid annotation index\n"); } if (!Integral::almostEqual(andx_00.getNearestOffset(2.64), offset_01)) { Console::put(L"invalid annotation index\n"); } if (!Integral::almostEqual(andx_00.getNearestOffset(2.65), offset_01)) { Console::put(L"invalid annotation index\n"); } if (!Integral::almostEqual(andx_00.getNearestOffset(2.76), offset_02)) { Console::put(L"invalid annotation index\n"); } if (!Integral::almostEqual(andx_00.getNearestOffset(2.77), offset_02)) { Console::put(L"invalid annotation index\n"); } if (!Integral::almostEqual(andx_00.getNearestOffset(3.12), offset_03)) { Console::put(L"invalid annotation index\n"); } if (!Integral::almostEqual(andx_00.getNearestOffset(3.24), offset_03)) { Console::put(L"invalid annotation index\n"); } // get the offsets // DoubleLinkedList annotations(DstrBase::USER); // this should return an empty list // andx_00.getByOffset(offset_00, annotations); if (annotations.length() != 0) { Console::put(L"invalid annotation index\n"); } // this should return an empty list // andx_00.getByOffset(offset_01, annotations); if (annotations.length() != 0) { Console::put(L"invalid annotation index\n"); } // this should return a single annotation (anno_01) // andx_00.getByOffset(offset_02, annotations); if (annotations.length() != 1) { Console::put(L"invalid annotation index\n"); } if (annotations.getFirst() != &anno_01) { Console::put(L"invalid annotation index\n"); } // this should return a single annotation (anno_01) // andx_00.getByOffset(offset_03, annotations); if (annotations.length() != 1) { Console::put(L"invalid annotation index\n"); } if (annotations.getFirst() != &anno_01) { Console::put(L"invalid annotation index\n"); } // get the annotation offsets // Annotation* annotation; // this should return a null pointer // annotation = andx_00.getAnnotationByOffset(offset_00); if (annotation != (Annotation*)NULL) { Console::put(L"invalid annotation index\n"); } // this should return a null pointer // annotation = andx_00.getAnnotationByOffset(offset_01); if (annotation != (Annotation*)NULL) { Console::put(L"invalid annotation index\n"); } // this should return a single annotation (anno_01) // annotation = andx_00.getAnnotationByOffset(offset_02); if (annotation != &anno_01) { Console::put(L"invalid annotation index\n"); } // this should return a single annotation (anno_01) // annotation = andx_00.getAnnotationByOffset(offset_03); if (annotation != &anno_01) { Console::put(L"invalid annotation index\n"); } // add/delete/exists features // AnnotationIndex andx_01; Annotation* anno_02 = new Annotation(anno_name_00, &ancr_00, &ancr_01, type_00); // add the feature-value pairs to the annotation // anno_02->setFeature(feat_00, value_00); anno_02->setFeature(feat_01, value_01); // insert an annotation // if (!andx_01.add(anno_02)) { Console::put(L"invalid annotation index\n"); } // add some features to the annotation // if (!andx_01.addFeature(anno_02, feat_00, value_00)) { Console::put(L"invalid annotation index\n"); } if (!andx_01.addFeature(anno_02, feat_01, value_01)) { Console::put(L"invalid annotation index\n"); } // verify that the features exists // if (!andx_01.existsFeature(feat_00, value_00)) { Console::put(L"invalid annotation index\n"); } if (!andx_01.existsFeature(feat_01, value_01)) { Console::put(L"invalid annotation index\n"); } // delete a feature form the index // if (!andx_01.deleteFeature(anno_02, feat_01)) { Console::put(L"invalid annotation index\n"); } // verify that the deletion was sucessfull // if (!andx_01.existsFeature(feat_00, value_00)) { Console::put(L"invalid annotation index\n"); } if (andx_01.existsFeature(feat_01, value_01)) { Console::put(L"invalid annotation index\n"); } // clean up memory // delete anno_02; // exit gracefully // Integral::exit(); }