string_of_text.h
上传用户:psq1974
上传日期:2007-01-06
资源大小:1195k
文件大小:2k
源码类别:

mpeg/mp3

开发平台:

C/C++

  1. /* Copyright (C) 1998, 1999 State University of New York at Stony Brook
  2.    Author: Andrew V. Shuvalov ( andrew@ecsl.cs.sunysb.edu )
  3.    Software license is located in file "COPYING"
  4. */
  5. #ifndef _string_of_text_h_
  6. #define _string_of_text_h_
  7. #include <vector>
  8. #include <string>
  9. #include <time.h>
  10. /** 
  11.  */
  12. class StringOfText {
  13.   string text;
  14.   struct tm _time;
  15.   /** just the same time as time_t */
  16.   time_t _time_t;
  17.   
  18. public:
  19.   StringOfText() {}
  20.   StringOfText( const StringOfText &s ) {
  21.     *this = s;
  22.   }
  23.   const StringOfText &operator =( const StringOfText &s ) {
  24.     if( this != &s ) {
  25.       text = s.text;
  26.       _time = s._time;
  27.       _time_t = s._time_t;
  28.     }
  29.     return *this;
  30.   }
  31.   void set( const string &t, const struct tm &tim ) {
  32.     text = t;
  33.     _time = tim;
  34.     _time_t = mktime( ( struct tm *) &tim );
  35.   }
  36.   const string &get_text() const { return text; }
  37.   const struct tm &get_time() const { return _time; }
  38.   time_t get_time_t() const { return _time_t; }
  39. };
  40. /** item for list of all places where the word occured 
  41.  */
  42. class WordOccurence {
  43.   unsigned int movieId;
  44.   unsigned int textLine;
  45.   unsigned int posInLine;
  46. public:
  47.   WordOccurence() {}
  48.   WordOccurence( unsigned int mId, unsigned int tl, unsigned int pil )
  49.     : movieId( mId ), textLine( tl ), posInLine( pil ) {}
  50.   WordOccurence( const WordOccurence &w ) {
  51.     *this = w;
  52.   }
  53.   const WordOccurence & operator =( const WordOccurence &w ) {
  54.     if( this != &w ) {
  55.       movieId = w.movieId;
  56.       textLine = w.textLine;
  57.       posInLine = w.posInLine;
  58.     }
  59.     return *this;
  60.   }
  61.   /** sometimes we need to sort them */
  62.   bool operator <( const WordOccurence &w ) const
  63.     {
  64.       if( movieId < w.movieId )
  65. return true;
  66.       if( movieId > w.movieId )
  67. return false;
  68.       if( textLine < w.textLine )
  69. return true;
  70.       if( textLine > w.textLine )
  71. return false;
  72.       if( posInLine < w.posInLine )
  73. return true;
  74.       if( posInLine > w.posInLine )
  75. return false;
  76.       return true;
  77.     }
  78.   bool is_near( const WordOccurence &w ) const
  79.     {
  80.       if( movieId != w.movieId )
  81. return false;
  82.       if( textLine + 5 < w.textLine )
  83. return false;
  84.       if( textLine - 5 > w.textLine )
  85. return false;
  86.       return true;
  87.     }
  88.   unsigned int get_movie_id() const { return movieId; }
  89.   unsigned int get_text_line() const { return textLine; }
  90. };
  91. /** list of word occurencies */
  92. typedef vector< WordOccurence > WordOccurencesT;
  93. #endif  //   _string_of_text_h_