
                                                            ++   848

                                   V
                    - 

   -    ,
  -   ,  . 
     ,   - 
-  .   C++  
     . , 
 ,  ,    . 
       .
   ,      OrthographicCamera 
PerspectiveCamera      Camera. 
  ,    ,     Camera.
          ,
     -  
 .
           , 
   . , PerspectiveCamera 
  Camera.  C++      
,          
      . ( 
          
 .)   :

   void lookAt( const Camera *pCamera );

   lookAt(),     Camera  
  ,    pCamera:    PerspectiveCamera, 
  OrthographicCamera   ,   - 
,     .
      lookAt()    ,    
 Camera.        
 :

   // :    Camera*
   OrthographicCamera ocam;
   lookAt( &ocam );
   // ...
   // :    Camera*
   PerspectiveCamera *pcam = new PerspectiveCamera;
   lookAt( pcam );

     lookAt()       Camera, 
  .      
  ,    lookAt()  .

                                                         ++   849

         ,    
   ,   .  
      ,  
    .      
        .
    ( )      
  (dynamic binding) (   
   ).  C++    
    .   
    -
,    .
     17    C++   -
       
,  , ,    ;
     Query,  
 ,    6.
     18     ,   
    .    
     16   .
     19       (RTTI),  
        . 
      ,    
 ,    .   ,
    .
    20      /
iostream.      ,  
,    .

17
                    17.    

     6       
         
TextQuery.         ,
      
   - . 
          Query 
 .  ,     
TextQuery   6     
 .
            
:

                                                         ++   850

   #include "TextQuery.h"

   int main()
   {
      TextQuery tq;
      tq.build_up_text();
      tq.query_text();
   }

   build_text_map()     - doit()   6. 
          
. ( ,         if,
and, but  ..  ,        
,   : , testifies  
testify,  marches  march.)      , 
          .
   query_text()         
    Query      . 
         , 
  build_text_map().        , 
  :

   Enter a query - please separate each item by a space.
   Terminate query (or session) with a dot( . ).

   ==> fiery && ( bird || shyly )

       fiery ( 1 ) lines match
       bird ( 1 ) lines match
       shyly ( 1 ) lines match
       ( bird || shyly ) ( 2 ) lines match
       fiery && ( bird || shyly ) ( 1 ) lines match

   Requested query: fiery && ( bird || shyly )

   ( 3 ) like a fiery bird in flight. A beautiful fiery bird, he tells her.

          :

    ,  Alice  untamed.   , 
      ,      ,
      . (     ).
    :

    ==> daddy
      
        daddy ( 3 ) lines match

    Requested query: daddy

    ( 1 ) Alice Emma has long flowing red hair. Her Daddy says
    ( 4 ) magical but untamed. "Daddy, shush, there is no such thing,"
    ( 6 ) Shyly, she asks, "I mean, Daddy, is there?"

                                                           ++   851

    Ŕ,     !.   ,
        . ,   
     1:

    ==> ! daddy

        daddy ( 3 ) lines match
        ! daddy ( 3 ) lines match

    Requested query: ! daddy

    ( 2 ) when the wind blows through her hair, it looks almost alive,
    ( 3 ) like a fiery bird in flight. A beautiful fiery bird, he tells her,
    ( 5 ) she tells him, at the same time wanting him to tell her more.

     Ȕ,     ||.   , 
            :

    ==> fiery || untamed

    fiery ( 1 ) lines match
    untamed ( 1 ) lines match
    fiery || untamed ( 2 ) lines match

    Requested query: fiery || untamed

   ( 3 ) like a fiery bird in flight. A beautiful fiery bird, he tells her,
   ( 4 ) magical but untamed. "Daddy, shush, there is no such thing,"

     Ȕ,     &&.   ,  
      ,   .    ,
          ,      :

    ==> untamed && Daddy

    untamed ( 1 ) lines match
    daddy ( 3 ) lines match
    untamed && daddy ( 1 ) lines match

   Requested query: untamed && daddy

   ( 4 ) magical but untamed. "Daddy, shush, there is no such thing,"

      :

   fiery && bird || shyly

       ,     
.       fiery bird 
shyly,    fiery bird  fiery shyly:

   ==> fiery && bird || shyly

   fiery ( 1 ) lines match
   bird ( 1 ) lines match
   fiery && bird ( 1 ) lines match
   shyly ( 1 ) lines match

   fiery && bird || shyly ( 2 ) lines match

                                                            ++   852

    Requested query: fiery && bird || shyly

    ( 3 ) like a fiery bird in flight. A beautiful fiery bird, he tells her,
    ( 6 ) Shyly, she asks, "I mean, Daddy, is there?"

        ,    
. :

   fiery && (bird || shyly)

   fiery bird  fiery shyly1.   
     .  ,    
     .

                    17.1.   

             .
       :

   NameQuery // Shakespeare
   NotQuery // ! Shakespeare
   OrQuery // Shakespeare || Marlowe
   AndQuery // William && Shakespeare

       - eval(),   
.  ,  NameQuery    , 
 (   )     (.  6.8);
 OrQuery         ..
 , 

   untamed || fiery

    OrQuery,     NameQuery  
.     ,     


   Alice || Emma && Weeks

 1 ,     ,   
    ,     ,  .  
        ,   ,   
   ,    ,   .

                                                          ++   853

 .      :  OrQuery,
  NameQuery    Alice  Emma,  
AndQuery.   AndQuery   NameQuery   Weeks.

   AndQuery
      OrQuery
         NameQuery ("Alice")
         NameQuery ("Emma")
      NameQuery ("Weeks")

         OrQuery,   &&.   
    NotQuery    AndQuery.    
,          ?  
  :

          OrQuery, AndQuery 
    NotQuery ,          
      ;

            ,   
           
     - eval().

   ,     ,   , 
       , 
  :

   //  - 
   union op_type {
      //       
      //  
      NotQuery *nq;
      OrQuery *oq;
      AndQuery *aq;
      string *word;
   };

   enum opTypes {
      Not_query=1, O_query, And_query, Name_query
   };

   class AndQuery {
   public:
      // ...
   private:
      /*
       * opTypes       
       * op_type -   
       */
      op_type _lop, _rop;
      opTypes _lop_type, _rop_type;
   };

            void*:

                                                            ++   854

   class AndQuery {
   public:
      // ...
   private:
      void * _lop, _rop;
      opTypes _lop_type, _rop_type;
   };

       ,    ,
   void*, ,      
  . (       C++,  
 C    .)
         ,   
    . ,   ,
  void*-,  eval()   AndQuery 
 :

   void AndQuery::eval()
   {
      //  - 
      //       
      //     
      switch( _lop_type ) {
         case And_query:
            AndQuery *paq = static_cast<AndQuery*>(_lop);
            paq->eval();
            break;
         case Or_query:
            OrQuery *pqq = static_cast<OrQuery*>(_lop);
            poq->eval();
            break;
        case Not_query:
           NotQuery *pnotq = static_cast<NotQuery*>(_lop);
           pnotq->eval();
           break;
        case Name_query:
           AndQuery *pnmq = static_cast<NameQuery*>(_lop);
           pnmq->eval();
           break;
      }
      //     
   }

            
         
  .
   -    , 
         .
,     eval()   AndQuery   
-  (eval()  ):

                                                            ++   855

   // - 
   //       
   // :  _lop  _rop -   
   //     

   void AndQuery::eval()
   {
      _lop->eval();
      _rop->eval();
   }

        - ,    
  ,  .

                 17.1.1. - 

      -   
  ?      ?
           
.         Query,  
    (      ). 
      ,      
,      ,     AndQuery, 
OrQuery, NotQuery  NameQuery.
       Query    -,  
   .    Query  , 
AndQuery,       .  ,
NameQuery     Query,      .
   NameQuery   ,  Query   
. (      ,    .)
     -     
 ,    .
        ,    
   ,      
 ,        
. ,   eval()    
   Query.  ,   :

   _rop->eval();

      .     ,
   ,    ,   
         
,      .      
  :    .

                                                              ++   856

          C++,      
           
.     eval()  :

   // pquery     ,   Query
   void eval( const Query *pquery )
   {
      pquery->eval();
   }

    ,        :

   int main()
   {
      AndQuery aq;
      NotQuery notq;
      OrQuery *oq = new OrQuery;
      NameQuery nq( "Botticelli" );

      // :    Query 
      //      
      eval( &aq );
      eval( &notq );
      eval( oq );
      eval( &nq );
   }

         eval()   ,  
  Query,   :

   int main()
   {
      string name( "Scooby-Doo" );
      // :  string     Query
      eval( &name );
   }


    eval()   

   pquery->eval();

    - eval()   
  ,   pquery.    pquery
   AndQuery, NotQuery, OrQuery  NameQuery.  
         
 eval().
   ,     ,   .
(          17.5.)

                                                            ++   857

    -    
,     ,    
  . (   . , , 
  ,         .)  C++ 
          
  .   ( -)    
   ,     .
        ,    
     ,       
   .   :

   //  
   int *pi;
   //    
   void *pvi;
   // pquery       Query 
   Query *pquery;

    C++        .
  void*   ,      
.      , 
         ,
,       . ( , 
   .)
    C++     :

            
         :

    Query *pquery = new NameQuery( "Class" );

      :

    pquery->eval();

      dynamic_cast  typeid (   
     19.1):

   if ( NameQuery *pnq = dynamic_cast< NameQuery* >( pquery )) ...

       ,     
AndQuery, NotQuery  OrQuery     Query*. :

                                                           ++   858

   class AndQuery {
   public:
      // ...
   private:
      Query *_lop;
      Query *_rop;
   };

          ,  
   Query,   ,     
  .    ,  ,
    ,     :

   _rop->eval();

    . 17.1   ,     Query 
    .       
 C++?

                                       Query

                        AndQuery OrQuery NotQuery NameQuery

                         . 17.1.   Query

     2.4      IntArray.
   ,   . 17.1,
:

   class Query { ... };
   class AndQuery : public Query { ... };
   class OrQuery : public Query { ... };
   class NotQuery : public Query { ... };
   class NameQuery : public Query { ... };

         .   
    :

   : - -

 -       public, protected, private (
        18.3),  - 
   . , Query    
     .
   ,    ,    .
   Query   ,   
   :

                                                             ++   859

   // : Query   
   class Query;
   class NameQuery : piblic Query { ... };

           ,  
  .      NameQuery
   :

   // :    
   //    
   class NameQuery : public Query;

         :

   //    ,
   //        
   class Query;
   class NameQuery;

        Query  IntArray (.  2.4)  
,  Query        .
  IntArray       
 .    Query,     
   ,      
 .  Query ,     . 
  IntArray    .
   -  
     Query   
 .

                                   17.1

        ,     
    .     :

    				-
    			 
    			   SEGA
       		   SONY
     - 		   Nintendo


                                   17.2

       ,   .
    :

   (a)    (gif, tiff, jpeg, bmp  ..)
   (b)   (, , ,   ..)

                                                        ++   860

   (c)   C++ (, , -  ..)

                         17.2.   

     2.4     ,      
 ,     ,   ,
   .   
         .
     ,     . -
, ,      (, , 
  ),  -, ,     
  .       .
   (   )      
.     ,     
    ,     
protected ().   -,    protected
 ,    ,    
   . (    private  
  ,   .)
           public   
,    - .  
   ,       . 
   ,    ,   
    ;  ,    ,  
        
.   ,     
,       ,  
,      .
         Query    
:

  (a)        
       Query?
  (b)      ?
  (c)       ?
  (d)  -       
      Query?
  (e)  -    ?

    ,      .   , 
-     ,
     ,  . 
          Query.

                          17.2.1.   

    Query :

                                                             ++   861

    ,      
    .     ,  
     ,   ,   
     (     );
    -,     .  
          Query,     
       ,       .

      :

   fiery || untamed

      :   ,
  ,     .
    eval()  display().
     eval()     ,   
     Query.    
    .   Query     
 .
      display(),    ,  
   .       
    ,  .    
          ,
     Query.
          ,   
 ,   :

   void doit( Query *pq )
  {
     //  
     pq->eval();
     //   Query::display()
     pq->display();
   }

        ?    
    ,    .  
  (, ),         short int.
    ,   build_text_map(),
        , 
 .        string,
 . ,  

   Alice Emma has long flowing red hair. Her Daddy says
   when the wind blows through her hair, it looks almost alive,
   like a fiery bird in flight. A beautiful fiery bird, he tells her,
   magical but untamed. "Daddy, shush, there is no such thing,"
   she tells him, at the same time wanting him to tell her more.

                                                              ++   862

   Shyly, she asks, "I mean, Daddy, is there?"

     ,   ( 
  ;        ; ,
       ):

   bird ((2,3),(2,9))
   daddy ((0,8),(3,3),(5,5))
   fiery ((2,2),(2,8))
   hair ((0,6),(1,6))
   her ((0,7),(1,5),(2,12),(4,11))
   him ((4,2),(4,8))
   she ((4,0),(5,1))
   tell ((2,11),(4,1),(4,10))

           .  ,  fiery 
 ,         .
        ,  
.   , ,  ,     
,    ,      
unique(),     (.  unique()  ).
        .  
  ,       
sort().
          ( set)    
 .        ,
     .    
       :

   set<short>* Query::_vec2set( const vector< location >* );

    _vec2set()  - Query.    ,
     ,    
 .     ,    , 
    . (    
   ,        Query.)
   ,     bird        
,         : (2).
    tell   ,       
  ; ,       : (2,4).
         :

   bird (2)
   daddy (0,3,5)
   fiery (2)
   hair (0,1)
   her (0,1,2,4)
   him (4)
   she (4,5)
   tell (2,4)

                                                            ++   863

       NameQuery,     
 ,        
   .
  NotQuery   ,     
. ,  

   ! daddy

  (1,2,4).     ,   
  . (    ,    ,
  ;  ,   .)   
NotQuery,        (0,1,2,3,4,5):
        set_difference()
   . (     
 (0,3,5).)
    OrQuery    ,    
 . ,   :

   fiery || her

    (0,1,2,4),   
 (2)   fiery   (0,1,2,4)   her.  
          .
          ,    
  .    AndQuery   
   ,       . ,  


   her && hair

     .    AndQuery
,    ,     her
hair.         ,   
:

   Alice Emma has long flowing red hair. Her Daddy says

       ,  :

   when the wind blows through her hair, it looks almost alive,

        her  hair   . 
,       : (1).

                                                            ++   864

       AndQuery,        
 . ,   AndQuery    
,          
 ,    (, ).   :

   fiery && ( hair || bird || potato )
   fiery && ( ! burr )

   NotQuery    AndQuery, ,     
,        ,   , 
  . (       
eval()   NotQuery  17.5.)
    ,        ,
    .    :  
         Query,
  .        
 .      ,  
    .
     ,       (
   )       
 ,  .      
,       ,   
    Query.
           ,  
 ,    .      
  ,      .    
   Query. (  display()   
  .)
           Query (,
       :   
  17.4  17.6):

                                                              ++   865

   #include <vector>
   #include <set>
   #include <string>
   #include <utility>

   typedef pair< short, short > location;
   class Query {
   public:
      //       17.4

      //      
      //    17.6

      //     
      virtual void eval() = 0;
      virtual void display () const;

      //    
      const set<short> *solution() const;
      const vector<location> *locations() const { return &_loc; }

      static const vector<string> *text_file() {return _text_file;}

   protected:
      set<short>* _vec2set( const vector<location>* );

      static vector<string> *_text_file;

      set<short> *_solution;
      vector<location> _loc;
   };

   inline const set<short> Query::solution()
   {
      return _solution
         ? _solution
         : _solution = _vec2set( &_loc );
   }

    

   virtual void eval() = 0;

  ,     eval()     Query
 :    ,    
         
.        
. (       17.5.)

                   17.2.2.   

         -   ,
     ,     
.  ,   NameQuery    eval().

                                                            ++   866

    ,     -,  
  string.
   ,        
   .       
 NameQuery,     .   
NameQuery ( ,    
   )  :

   typedef vector<location> loc;

   class NameQuery : public Query {
   public:
      // ...

      //    Query::eval()2
      virtual void eval();

     //  
     string name() const { return _name; }

      static const map<string,loc*> *word_map() { return _word_map; }
   protected:
      string _name;
      static map<string,loc*> *_word_map;
   };

    NotQuery       
eval()      .  
      ,      
Query.   NotQuery, ,     
,    ,        .
,   :

   ! daddy

   NotQuery    :

   daddy ((0,8),(3,3),(5,5))

    ,      ,    
   (1,2,4).  ,        
(0),   (8),      (3),   (3),   
   (5),   (5).

  2     ,  eval(), 
        virtual . 
            .

                                                                ++   867

            
  ,    (, )   
  (      17.5,   
 eval()  NotQuery).   ,     
 NotQuery.
      NotQuery (   ,  
   ):

   class NotQuery : public Query {
   public:
      // ...

      //  :     virtual
      //  Query::eval()
      virtual void eval();

      //    
      const Query *op() const { return _op; }
      static const vector< location > * all_locs() {
                                 return _all_locs; }
   protected:
      Query *_op;
      static const vector< location > *_all_locs;
   };

    AndQuery  OrQuery   ,     
 .         ,
         Query.  ,
       eval().  
 OrQuery:

   class OrQuery : public Query {
   public:
      // ...

      virtual void eval();

      const Query *rop() const { return _rop; }
      const Query *lop() const { return _lop; }

   protected:
      Query *_lop;
      Query *_rop;
   };

     AndQuery         . 
     AndQuery      ,
    . ,   :

   tell && her && magical

                                               ++   868

        :

   like a fiery bird in flight. A beautiful fiery bird, he tells her,
   magical but untamed. "Daddy, shush, there is no such thing,"

    ,      , :

   her ((0,7),(1,5),(2,12),(4,11))
   magical ((3,0))
   tell ((2,11),(4,1),(4,10))

     eval()  AndQuery  ,      (2),
    ,   magical  her .  
  ,    ,   
 . ( eval()      17.5.) ,
 AndQuery:

   class AndQuery : public Query {
   public:
      //     17.4
      virtual void eval();

      const Query *rop() const { return _rop; }
      const Query *lop() const { return _lop; }

      static void max_col( const vector< int > *pcol )
      { if ( !_max_col ) _max_col = pcol; }

   protected:
      Query *_lop;
      Query *_rop;
      static const vector< int > *_max_col;
   };

                                       17.2.3. 

             
     Query.   :

   Query *pq = new NmaeQuery( "Monet" );

      Query    pq.  
:

   pq->eval();

    eval()   ,  
  pq,       NameQuery. 

   pq->display();

                                                          ++   869

    display()  Query.   
      ,   
pq.          ,  
          
 Query. display()     , 
  ,     .  
 (    ,     
):

   void Query::display()
   {
      if ( ! _solution->size() ) {
         cout << "\n\t, "
              << "      .\n"
              << endl;
      }

      set<short>::const_iterator it = _solution->begin(), end_it = _solution->end();

      for ( ; it != end_it; ++it ) {
         int line = *it;
         //       0...
         cout << "(" << line+1 << " ) "
              << (*_text_file)[line] << '\n';
      }

      cout << endl;
   }

           Query.   
,        ,  
,   .     ,  
   .       
    C++.

                                 17.3

           
 17.1 ( 17.1).      
,    ,      , 
, , ,      . (:
LibMember    ,     
 ; Date  ,   .)

                                                                ++   870

   class Library {
   public:
      bool check_out( LibMember* ); // 
      bool check_in ( LibMember* ); //  
      bool is_late( const Date& today ); // 
      double apply_fine(); //  
      ostream& print( ostream&=cout );

      Date* due_date() const; //   
      Date* date_borrowed() const; //  

      string title() const; // 
      const LibMember* member() const; // 
   };

                                    17.4

           ,  
   17.2 ( 17.1).   ,  
   .

                                      17.5

       :

   class base { ... };

   (a) class Derived : public Derived { ... };
   (b) class Derived : Base { ... };
   (c) class Derived : private Base { ... };
   (d) class Derived : public Base;
   (e) class Derived inherits Base { ... };

                    17.3.     

          . 
       ,   
-  .      ,
    ,    ,  
   . ,   NameQuery   
Query,   _loc  _solution,  ,  NameQuery,  
   _name.
       ,   ,  
,    . (    
       .) :

                                                                ++   871

   void NameQuery::display_partial_solution( ostream &os )
   {
      os << _name
         << " is found in "
         << (_solution ? _solution->size() : 0)
         << " lines of text\n";
   }

         -  : 
  ,            :

   NameQuery nq( "Frost" );
   //  NameQuery::eval()
   nq.eval();
   //  Query::display()
   nq.display();

     (   ) -:

   void NameQuery::match_count()
   {
      if ( ! _solution )
         //  Query::_vec2set()
         _solution = _vec2set( &_loc );
      return _solution->size();
   }

            ,  
    :

   class Diffident {
   public: // ...
   protected:
      int _mumble;
      // ...
   };

   class Shy : public Diffident {
   public: // ...
   protected:
      //  Diffident::_mumble 
      string _mumble;
      // ...
   };

                                                             ++   872

      Shy    _mumble
    _mumble  Shy ( string),   
    :

   void Shy::turn_eyes_down()
   {
      // ...
      _mumble = "excuse me"; // 
      // : int Diffident::_mumble 
      _mumble = -1;
   }

         .    
 ,     ,   
          
 .     -
turn_eyes_down():

   void Shy::turn_eyes_down()
   {
      // ...
      _mumble = "excuse me"; // 
      // :     
      Diffident::_mumble = -1;
   }

   -       
 :

   class Diffident {
   public:
      void mumble( int softness );
      // ...
   };

   class Shy : public Diffident {
   public:
      //   - Diffident::_mumble,
      //    
      void mumble( string whatYaSay );
      void print( int soft, string words );
      // ...
   };

    -          
:

                                                                 ++   873

   Shy simon;

   // : Shy::mumble( string )
   simon.mumble( "pardon me" );

   // :     string
   // Diffident::mumble( int ) 
   simon.mumble( 2 );

          ,   
 ,   .      , 
        .      ,
    - turn_aside()

   class Diffident {
   public:
      void turn_aside( );
      // ...
   };

   class Shy : public Diffident {
   public:
      //  
      // Diffident::turn_aside()
      void turn_aside();
      // ...
   };


     ,     . 
 ,        
,   .
          -  
 ?       
    ?  :

   class Shy : public Diffident {
   public:
      //      
      //     
      void mumble( string whatYaSay );
      void mumble( int softness ) {
      Diffident::mumble( softness ); }
      // ...
   };

      C++      using-:

                                                               ++   874

   class Shy : public Diffident {
   public:
      //   C++ using-
      //   
      //     
      void mumble( string whatYaSay );
      using Diffident::mumble;
      // ...
   };

     , using-       
  .       
 ,    - 
. (  using-    ,  . 
,         ,   
       ,
,      .)
           . 
 :

   class Query {
   public:
      const vector<location>* locations() { return &_loc; }
      // ...
   protected:
      vector<location> _loc;
      // ...
   };

   ,  ,   Query,     
_loc,          
  .        
  _loc    ,    .
        
   :

   bool NameQuery::compare( const Query *pquery )
   {
      // :    Query
      int myMatches = _loc.size();
      // :      
      //   Query
      int itsMatches = pquery->_loc.size();
      return myMatches == itsMatches;
   }

                                                               ++   875

     NameQuery         Query 
  .        
   this (.  13.4).      
  compare()    -
location():

   bool NameQuery::compare( const Query *pquery )
   {
      // :    Query
      int myMatches = _loc.size();

      // :    
      int itsMatches = pquery->locations()->size();
      return myMatches == itsMatches;
   }

        .  _loc  
   Query,   compare()   ,  
 .         
     ,    ,  
 .
              
   :

   bool NameQuery::compare( const NameQuery *pname )
   {
      int myMatches = _loc.size(); // 
      int itsMatches = name->_loc.size(); //  

      return myMatches == itsMatches;
   }

            
    ,    ,       
    .
        Query   
NameQuery:

   Query *pb = new NameQuery( "sprite" );

      ,     Query, :

   pb->eval(); //  NameQuery::eval()

                                                            ++   876

   NameQuery.     ,
  Query    NameQuery,   
    NameQuery   pb  :

  (a)   Query  NameQuery    -
         ,   pb     Query;
  (b)   Query  NameQuery   ,   pb
           Query;
  (c)   NameQuery   ,   Query,
       suffix(),      pb   
      :

      // : suffix() -    Query
      pb->suffix();

        -  NameQuery 
    pb    :

    // : _name -    Query
    pb->_name;

           :

    // :   Query    NameQuery
    pb->NameQuery::_name;

    C++            
-,  ,   ( ) 
  ,   ,     .
 -      , 
  ,   (   )
  ,  pb.
        ,      
:

     -      
     - ,      .   
         ;
      .    
      ,       (
        [LIPPMAN96a]).

      Query    _text_file:

   static vector<string> *_text_file;

                                                             ++   877

        NameQuery   _text_file,
   ? .       
 ,    .    
 ,     _text_file.  
         :

   nameQueryObject._text_file; // 

   ,          
  ,       :

   class Query {
   friend class NameQuery;
   public:
      // ...
   };

     NameQuery        
,   ,       
  Query.
        NameQuery  StringQuery?   
   AndQuery,  

   beautiful && fiery && bird

  :

   "beautiful fiery bird"

     StringQuery   NameQuery    Query?
.    .    
 ,       .  
       ,    
    . ,   StringQuery 
       Query.   
,  Query    .

                                        17.6

         :

                                                             ++   878

   class Base {
   public:
      foo( int );
      // ...
   protected:
      int _bar;
      double _foo_bar;
   };

   class Derived : public Base {
   public:
      foo( string );
      bool bar( Base *pb );
      void foobar();
      // ...
   protected:
      string _bar;
   };


          :

   Derived d; d.foo( 1024 );

   (b) void Derived::foobar() { _bar = 1024; }

   (c) bool Derived::bar( Base *pb )
        { return _foo_bar == pb->_foo_bar; }


               17.4.     

   ,          ,
  ,  ,    .
, NameQuery    Query  - string. 
        
 :

   class NameQuery : public Query {
   public:
      // ...
   protected:
      bool _present;
      string _name;
   };

    _present   false,   _name   .

                                                           ++   879

    ,   NameQuery   .  
   

   NameQuery nq;

      Query,    
  string (   _name).  _present 
,      . 
 ,        
NameQuery:

   inline NameQuery::NameQuery() { _present = false; }

      nq     :  
 Query,   string    _name   
NameQuery.
          Query?    
,   .
          -  
   (      , 
  ;  .   14.5):

   inline NameQuery::NameQuery( const string &name )
      : _name( name ), _present( false )
   {}

            
    .    
  string  name,     Query 
,   ploc:

   inline NameQuery::NameQuery( const string &name, vector<location> *ploc )
      : _name( name ), Query( *ploc ), _present( true )
   {}

    Query     ,   
    _name.    :

      .    ,  
            ,     
      . (        
     18.)

     -.       ,  
          ,       
     ( .  14.5).

                                                              ++   880

       .

           
     ,     . 
         
      . (
      
.)
            
      ,    
    Query,    
  .        .

                          17.4.1.   

          : _solution  _loc:

   class Query {
   public:
      // ...
   protected:
      set<short> *_solution;
      vector<location> _loc;
      // ...
   };

    Query       
_solution.   _loc    
vector.    :

   inline Query::Query(): _solution( 0 ) {}

    Query     ,    
:

   inline Query::Query( const vector< locaton > &loc )
      : _solution( 0 ), _loc( loc )
   {}

        NameQuery,    
      .    
     .   
       - eval(). (
   ,   .  -
eval()    17.5.)
        ?     
,   ,  Query      

                                                               ++   881

        .   
  ,  :

   class Query {
   public:
      // ...
   protected:
      Query();
      // ...
   };

       Query     : 
    Query     ,  
       NameQuery.   
,  NameQuery    Query. (   
,          
  .       
 AndQuery, OrQuery  NotQuery    .)

   class Query {
   public:
      // ...
   protected:
      Query();
      // ...
   private:
      explicit Query( const vector<location>& );
   };

(   ; ,   _loc 
 eval()  NameQuery.      
       .)

                      17.4.2.   

     NameQuery    .   ,
 ,        :

   class NameQuery : public Query {
   public:
      explicit NameQuery( const string& );
      NameQuery( const string&, const vector<location>* );
      // ...
   protected:
      // ...
   };

                                                             ++   882

           . 
    string,    
 _name.      Query  :

   inline NameQuery::NameQuery( const string &name ) // Query::Query()  
      : _name( name )
   {}

              .
        .   
   Query. ( ,  _present   
,        NameQuery.)

   inline NameQuery::NameQuery( const string &name, vector<location> *ploc )
      : _name( name ), Query( *ploc )
   {}

      :

   string title( "Alice" );
   NameQuery *pname;

   // ,   "Alice"   
   //  ,      
   if ( vector<location> *ploc = retrieve_location( title ))
      pname = new NameQuery( title, ploc );
   else pname = new NameQuery( title );

       NotQuery, OrQuery  AndQuery   
,        :

   inline NotQuery::NotQuery( Query *op = 0 ) : _op( op ) {}

   inline OrQuery::OrQuery( Query *lop = 0, Query *rop = 0 )
      : _lop( lop ), _rop( rop )
   {}

   inline AndQuery::AndQuery( Query *lop = 0, Query *rop = 0 )
      : _lop( lop ), _rop( rop )
   {}

                                                             ++   883

(  17.7        
   .)

                     17.4.3.   

       Query   ,   
  . , AndQuery  OrQuery   
,    -    .   
  -,   ,     BinaryQuery.
   Query    17.2:

                                 Query
                               BinaryQuery
                           AndQuery     OrQuery

   . 17.2.   

    BinaryQuery      , , 
     .   eval() 
  ,    ,   Query, 
 BinaryQuery   . (    
   17.5.)
    -    lop()  rop(),    , 
,  BinaryQuery,     .  
 _lop  _rop,    ,    BinaryQuery 
   .   
       BinaryQuery:

   class BinaryQuery : public Query {
   public:
      const Query *lop() { return _lop; }
      const Query *rop() { return _rop; }
   protected:
      BinaryQuery( Query *lop, Query *rop )
         : _lop( lop ), _rop( rop )
      {}
      Query *_lop;
      Query *_rop;
   };
                                                            ++   884

    ,       
   eval():

   // !    
   class OrQuery : public BinaryQuery {
   public:
      virtual void eval();
   };

   class AndQuery : public BinaryQuery {
   public:
      virtual void eval();
   };

      ,     ,   .  
    ,     
 :

   // :    AndQuery
   AndQuery proust( new NameQuery( "marcel" ),
   new NameQuery( "proust " ));

     :   AndQuery  ,
   .
    ,  AndQuery  OrQuery   BinaryQuery 
 ,    - lop()  rop().    
  . (     ,  
   . ,  ,  
AndQuery   ,    : 
       AndQuery
  .      . 
     AndQuery,  ,   .
 ,   new  delete ,  
   .)
          . 
  AndQuery  OrQuery     
       BinaryQuery.  
 :

                                                                 ++   885

   // :    
   class OrQuery : public BinaryQuery {
   public:
      OrQuery( Query *lop, Query *rop )
         : BinaryQuery( lop, rop ) {}
      virtual void eval();
   };

   class AndQuery : public BinaryQuery {
   public:
      AndQuery( Query *lop, Query *rop )
         : BinaryQuery( lop, rop ) {}
      virtual void eval();
   };

          
     ( 
    ,      : .  18.5).
,    Query    
 AndQuery   .
       AndQuery  OrQuery   
:   Query,     BinaryQuery 
  AndQuery  OrQuery. (   
       .) 
 ,   BinaryQuery,    
,       .
           ,
       ,       
.      , 
   ,         
.

                        17.4.4.   

      ,   
 AndQuery  OrQuery (    
)   .      
   AndQuery,       
  .   , :

        ,     
     ,    .   
        ,       , 
         .  ,
    ,        ,   
    ,         ;

                                                                ++   886

     ,        ,
         ,   
        .    
          ,    , 
       ,    .

               
,     . 
   ,      
    ,      .
     ,     
.    ,   ,    
   .
    C++   ,   
,    ,   
,     . ( ,   , 
    ,     
  ,    ). ,
        
.  ,       
, ;     , ,  
 Query,    .

                               17.4.5. 

         , 
      (  ), 
   -. ,    
NameQuery:

   NameQuery nq( "hyperion" );

    :   NameQuery, 
 string   _name     .  
      .
       Query     (  
   ):

   inline Query::~Query(){ delete _solution; }

   inline NotQuery::~NotQuery(){ delete _op; }

   inline OrQuery::~OrQuery(){ delete _lop; delete _rop; }

   inline AndQuery::~AndQuery(){ delete _lop; delete _rop; }

     :

                                                              ++   887

        NameQuery,   
            .
         string   _name 
    ;

         delete   
      Query*.     Query,    
     ,     ,   
       Query . (   
               
      .)

       ,    ,  
     NotQuery, OrQuery  AndQuery,   .
          delete. 
      ,     
       .       
  .
     17.7       
 Query    UserQuery.    
.         new 
delete   . ,    .
 new    , ,     
 .   delete  :   ,  
     delete.

                                     17.7

            
,      17.2 ( 17.1).

                                       17.8

      OrQuery ,      BinaryQuery.

                                      17.9

        :

   class Object {
   public:
      virtual ~Object();
      virtual string isA();
   protected:
      string _isA;
   private:
      Object( string s ) : _isA( s ) {}
   };

                                       17.10

      :

                                                                ++   888

   class ConcreteBase {
   public:
      explicit ConcreteBase( int );
      virtual ostream& print( ostream& );
      virtual ~Base();
      static int object_count();
   protected:
      int _id;
      static int _object_count;
   };

       :

   (a) class C1 : public ConcreteBase {
       public:
          C1( int val )
             : _id( _object_count++ ) {}
          // ...
      };

   (c) class C3 : public C2 {
       public:
          C3( int val )
            : C2( val ), _object_count( val ) {}
          // ...
       };

   (d) class C4 : public ConcreteBase {
       public:
          C4( int val )
             : ConcreteBase ( _id+val ){}
          // ...
       };

                               17.11

       C++    
      . ,

                                                          ++   889

  ,    1986 .   ,  
  ?

               17.5.       

     -    .   
   ,      
( ,    ),    :

   void Query::display( Query *pb )
   {
      set<short> *ps = pb->solutions();
      // ...
      display();
   }

     pb   Query*.      solutions()
 -  Query.   display() 
   this.    this  
Query*,    -  Query.
      ,     virtual:

   class Query {
   public:
      virtual ostream& print( ostream* = cout ) const;
      // ...
   };

    - ,       ,
      ( ,   
),    .       
       .    
       .
    ,    ,   
  ,      . 
        .
   :

   NameQuery nq( "lilacs" );
   // :  nq ""   Query
   Query qobject = nq;

    qobject  nq  :  qobject 
 nq,     Query,  qobject 

                                                           ++   890

  NameQuery.  nq,  NameQuery,  
 qobject,       , 
  Query.        
,    :

   void print ( Query object, const Query *pointer, const Query &reference )
   {
      //     ,
      //   print() 
      pointer->print();
      reference.print();
 
      //   Query::print()
      object.print();
   }

   int main()
   {
      NameQuery firebird( "firebird" );
      print( firebird, &firebird, firebird );
   }

          pointer   reference
   ;    
NameQuery::print().     object    
Query::print(). ( ,     ,
   18.6.2.)
          
    .   - 
    - .

                      17.5.1.  /

     ,    ,     
    :

   ostream& print( ostream &os = cout ) const;

    print()   ,     
,         Query*. ,  
AndQuery      :

   ostream& AndQuery::print( ostream &os ) const
   {
      _lop->print( os );
      os << " && ";
      _rop->print( os );
   }

                                                                 ++   891

     print()      Query,
         AndQury, OrQuery  NotQuery,
       Query*. 
  Query   print()  .   
   ,     :

   class Query {
   public:
      virtual ostream& print( ostream &os=cout ) const {}
      // ...
   };

     ,       ,  
    virtual.      
 ,   virtual  . ,  
print()    :

   // :   virtual  
   //    
   virtual ostream& Query::print( ostream& ) const { ... }

   ,      ,    
   (,       ). 
         
,           ,
     .     
 ,  ,      .
         print()   
 ,       . , 


   fiery && bird || shyly

    

   fiery bird

  

   shyly

     , 

                                                              ++   892

   fiery && ( bird || hair )

     

   fiery bird



   fiery hair

      print()       ,  
    .    ,
      Query   ,  
    (      
):

   class Query {
   public:
      // ...
      //  _lparen  _rparen
      void lparen( short lp ) { _lparen = lp; }
      void rparen( short rp ) { _rparen = rp; }

      //  _lparen  _rparen
      short lparen() { return _lparen; }
      short rparen() { return _rparen; }

       //     
       void print_lparen( short cnt, ostream& os ) const;
       void print_rparen( short cnt, ostream& os ) const;
   protected:
      //     
      short _lparen;
      short _rparen;
      // ...
   };

   _lparen    ,  _rparen   ,   
   . (  17.7  ,   
      .)    
   :

   ==> ( untamed || ( fiery || ( shyly ) ) )
   evaluate word: untamed
      _lparen: 1
      _rparen: 0
   evaluate Or
      _lparen: 0
      _rparen: 0

                                                              ++   893

   evaluate word: fiery
      _lparen: 1
      _rparen: 0
   evaluate 0r
      _lparen: 0
      _rparen: 0
   evaluate word: shyly
      _lparen: 1
      _rparen: 0
   evaluate right parens:
   _rparen: 3

   ( untamed ( 1 ) lines match
   ( fiery ( 1 ) lines match
   ( shyly ( 1 ) lines match
   ( fiery || (shyly ( 2 ) lines match3
   ( untamed || ( fiery || ( shyly ))) ( 3 ) lines match

   Requested query: ( untamed || ( fiery || ( shyly ) ) )
   ( 3 ) like a fiery bird in flight. A beautiful fiery bird, he tells her,
   ( 4 ) magical but untamed. "Daddy, shush, there is no such thing,"
   ( 6 ) Shyly, she asks, "I mean, Daddy, is there?"

    print()   NameQuery:

   ostream& NameQuery::print( ostream &os ) const
   {
      if ( _lparen )
         print_lparen( _lparen, os );
         os << _name;

      if ( _rparen )
         print_rparen( _rparen, os );
         return os;
   }

      :

   class NameQuery : public Query {
   public:
      virtual ostream& print( ostream &os ) const;
      // ...
   };

            
,    . ,     
const     ,   print()  NameQuery 
     .    

   3 !    ,  OrQuery   
         .

                                                            ++   894

    : ,   
 ,     ,   
 ,     .    
     Query*,     
  NameQuery*. (     clone()  , 
 .)     print()  NotQuery:

   class NotQuery : public Query {
   public:
      virtual ostream& print( ostream &os ) const;
      // ...
   };

   ostream& NotQuery::print( ostream &os ) const
   {
      os << " ! ";

      if ( _lparen )
         print_lparen( _lparen, os );
      _op->print( os );

      if ( _rparen )
        print_rparen( _rparen, os );

      return os;
   }

   ,  print()  _op  .
          AndQuery  OrQuery 
  .      AndQuery:

   class AndQuery : public Query {
   public:
      virtual ostream& print( ostream &os ) const;
      // ...
   };

                                                          ++   895

   ostream& AndQuery::print( ostream &os ) const
   {
      if ( _lparen )
         print_lparen( _lparen, os );
      _lop->print( os );

      os << " && ";
      _rop->print( os );

      if ( _rparen )
         print_rparen( _rparen, os );

      return os;
   }

       print()     Query
   ostream   ,   :

   cout << "   ";
   Query *pq = retrieveQuery();
   pq->print( cout );

      .     
  Query ,        , 
     iostream:

   Query *pq = retrieveQuery();
   cout << "    "
        << *pq
        << "   :\n";

          , 
    ostream.      
 :

   inline ostream& operator<<( ostream &os, const Query &q )
   {
      //   print()
      return q.print( os );
   }

   

   AndQuery query;
   //   ...

                                                             ++   896

   cout << query << endl;

     ostream,     

   q.print( os )

 q    query  AndQuery,  os   cout.    
 :

   NameQuery query2( "Salinger" );
   cout << query2 << endl;

     print()   NameQuery. 

   Query *pquery = retrieveQuery();
   cout << *pquery << endl;

     print(),    ,
  pquery     .

                         17.5.2.   

        ,       
 ,         
  .        :
AndQuery, OrQuery  ..        
    ,      
.     ,    
    .
     ,     Query.     
    ,   
,   :

   void doit_and_bedone( vector< Query* > *pvec )
   {
      vector<Query*>::iterator it = pvec->begin(), end_it = pvec->end();

      for ( ; it != end_it; ++it )
      {
         Query *pq = *it;
         cout << " " << *pq << endl;
         pq->eval();
         pq->display();
         delete pq;
      }
   }

                                                                ++   897

           
      ,   , 
      Query  
  .
      Query,    , 
       ,    
    .      ,
    ,    ,   , 
   ,     .
    Query   ,      , 
          
.   ,       .
     .
      , ,   
  ,      
,     .    .
   :

   class Query {
   public:
      //    
      virtual ostream& print( ostream&=cout ) const = 0;
      // ...
   };

   ,       .
   ,  ( )     , 
    .    
     . (   
      .) :

   //   Query      ,
   //       
   //  Query
   // :  Query   NameQuery
   Query *pq = new NameQuery( "Nostromo" );
   // :  new    Query
   Query *pq2 = new Query;

             
    .    ,   
  Query.

                                                                ++   898

                     17.5.3.    

           
,        ,  
. ,      isA()  
      Query:

   Query *pquery = new NameQuery( "dumbo" );

   // isA()      
   //    NameQuery::isA()
   pquery->isA();

   // isA     
   //    Query::isA
   pquery->Query::isA();

      Query::isA()       
isA()    Query,  pquery   NameQuery.
       ?  ,  . 
        
 ,   ,     
.  ,  ,    display()  Camera
  ,    ,   display() 
 PerspectiveCamera  ,   
 .       ,   
,      Camera.   ,  
  ,       . 
,   Camera  ,     
      .
      ,      
,         ,
     .
     print()   AndQuery  OrQuery   , 
 ,   .   
,      .     
  BinaryQuery (   AndQuery  OrQuery).  
        string    .
   ,  print()   :

                                                            ++   899

   class BinaryQuery : public Query {
   public:
      BinaryQuery( Query *lop, Query *rop, string oper )
         : _lop(lop), _rop(rop), _oper(oper) {}
      ~BinaryQuery() { delete _lop; delete _rop; }
      ostream &print( ostream&=cout, ) const = 0;
   protected:
      Query *_lop;
      Query *_rop;
      string _oper;
   };

       BinaryQuery  print(),    
  AndQuery  OrQuery:

   inline ostream& BinaryQuery::print( ostream &os ) const
   {
      if ( _lparen )
         print_lparen( _lparen, os );

      _lop->print( os );
      os << ' ' << _oper << ' ';
      _rop->print( os );

      if ( _rparen )
         print_rparen( _rparen, os );
 
      return os;
   }

   ,     .   ,  
  print()    ,  
 BinaryQuery    .   
   BinaryQuery  .
     ,     BinaryQuery  
print()       AndQuery  OrQuery.
         ,     :
        , 
  :

   inline ostream& AndQuery::print( ostream &os ) const
   {
      // :   
      //  BinaryQuery::print 
      BinaryQuery::print( os );
   }

                                                              ++   900

                     17.5.4.      

       :

   #include <iostream>

   class base {
   public:
      virtual int foo( int ival = 1024 ) {
         cout << "base::foo() -- ival: " << ival << endl;
         return ival;
      }
      // ...
   };

   class derived : public base {
   public:
      virtual int foo( int ival = 2048 ) {
         cout << "derived::foo() -- ival: " << ival << endl;
         return ival;
      }
      // ...
   };

     ,       foo() 
      1024:

   base b;
   base *pb = &b;
   //  base::foo( int )
   // ,    1024
   pb->foo();

    ,  ,      foo()  
    2048:

   derived d;
   base *pb = &d;
   //  derived::foo( int )
   // ,    2048
   pb->foo();

     C++     .  
     :

                                                              ++   901

   int main()
   {
      derived *pd = new derived;
      base *pb = pd;
      int val = pb->foo();
      cout << "main() : val  base: "
           << val << endl;
      val = pd->foo();
      cout << "main() : val  derived: "
           << val << endl;
   }

          :

   derived::foo() -- ival: 1024
   main() : val  base: 1024

   derived::foo() -- ival: 2048
   main() : val  derived: 2048

       foo()     ,
        
  ,  pd  pb.   foo()  
     ,       
,    .   foo()  pb  
    base::foo()   1024.   foo()
  pd,       
derived::foo()  2048.
              
     ,    ,  
        ?
             
 foo()    ,      ,
   . ,  1024  2048   
.      ,  foo()
  base,       derived.
      - ,    ,  foo(), 
   ?  ,   
  .       ,
    ,     
.   ,       
  ,     , 
   :

                                                           ++   902

   void base::foo( int ival = base_default_value )
   {
      int real_default_value = 1024; //    
      if ( ival == base_default_value )
         ival = real_default_value;
      // ...
   }

    base_default_value  ,     ,
    ,      .
        :

   void derived::foo( int ival = base_default_value )
   {
      int real_default_value = 2048;
      if ( ival == base_default_value )
         ival = real_default_value;
      // ...
   }


                       17.5.5.  

         delete:

   void doit_and_bedone( vector< Query* > *pvec )
   {
      // ...
      for ( ; it != end_it; ++it )
      {
         Query *pq = *it;
         // ...
         delete pq;
      }
   }

      ,  delete  
  ,    pq. ,  
 Query :

                                                              ++   903

   class Query {
   public:
      virtual ~Query() { delete _solution; }
      // ...
   };

       Query   
. doit_and_bedone()  .
       :   
 ,   pq   .   
     .   
,      . ,  pq 
   AndQuery, 

   delete pq;

     AndQuery    .
     BinaryObject,   
   Query.
      

   class Query {
   public: // ...
   protected:
      virtual ~Query();
      // ...
   };

   class NotQuery : public Query {
   public:
      ~NotQuery();
      // ...
   };

    NotQuery      NotQuery,
           Query. 
,       ,  
 :

   int main()
   {
      Query *pq = new NotQuery;
      // :   
      delete pq;
   }

                                                            ++   904

    :         
  ,     . ,
     ,      .

                       17.5.6.   eval()

       Query    eval() (   
    ).     -,
  eval()    Query ,    
 :

   class Query {
   public:
      virtual void eval() = 0;
      // ...
   };
 
      eval()      
 .     ,       . 
   ,   ,   NameQuery
   .    NameQuery  eval() .
            Query. ?
  NameQuery    ,    
 .       ,    
 ,         .  
 eval()  :

   class NameQuery : public Query {
   public:
      virtual void eval() {}
      // ...
   };

     NotQuery    ,    .
     _loc  NotQuery    (, ).
    :

                                                                  ++   905

   void NotQuery::eval()
   {
      //  
      _op->eval();

      // _all_locs -  ,     ,
      //     NotQuery:
      // static const vector<locations>* _all_locs
      vector< location >::const_iterator
         iter = _all_locs->begin(),
         iter_end = _all_locs->end();

      //   ,    
      set<short> *ps = _vec2set( _op->locations() );

      //   ,    ,
      //     _loc
      for ( ; iter != iter_end; ++iter )
      {
         if ( ! ps->count( (*iter).first )) {
            _loc.push_back( *iter );
      }
   }

        NotQuery.    0, 3
 5  . (,       
  0;      ,    
.)      ,  
    1,2  4. (   ,   
 .)

   ==> ! daddy
   daddy ( 3 ) lines match
   display_location_vector:
      first: 0 second: 8
      first: 3 second: 3
      first: 5 second: 5
   ! daddy ( 3 ) lines match
   display_location_vector:
      first: 1 second: 0
      first: 1 second: 1
      first: 1 second: 2
      ...
      first: 1 second: 10
      first: 2 second: 0
      first: 2 second: 1
      ...
      first: 2 second: 12
      first: 4 second: 0
      first: 4 second: 1
      ...
      first: 4 second: 12

   Requested query: ! daddy
   ( 2 ) when the wind blows through her hair, it looks almost alive,
   ( 3 ) like a fiery bird in flight. A beautiful fiery bird, he tells her,
   ( 5 ) she tells him, at the same time wanting him to tell her more.

      OrQuery     . 
    merge().  merge()  

                                                             ++   906

 (, ),   -   . 
  :

   class less_than_pair {
   public:
      bool operator()( location loc1, location loc2 )
      {
         return (( loc1.first < loc2.first ) ||
                 ( loc1.first == loc2.first ) &&
                 ( loc1.second < loc2.second ));
      }
   };

   void OrQuery::eval()
   {
      //     
      _lop->eval();
      _rop->eval();

      //      
      vector< location, allocator >::const_iterator
         riter = _rop->locations()->begin(),
         liter = _lop->locations()->begin(),
         riter_end = _rop->locations()->end(),
         liter_end = _lop->locations()->end();

      merge( liter, liter_end, riter, riter_end,
             inserter( _loc, _loc.begin() ),
             less_than_pair() );
   }

        OrQuery,      
       . (  ,  
    1,      0.)

   ==> fiery || untamed
   fiery ( 1 ) lines match
   display_location vector:
      first: 2 second: 2
      first: 2 second: 8

   untamed ( 1 ) lines match
   display_location vector:
      first: 3 second: 2

   fiery || untamed ( 2 ) lines match
   display_location vector:
      first: 2 second: 2
      first: 2 second: 8
      first: 3 second: 2
    Requested query: fiery || untamed
   ( 3 ) like a fiery bird in flight. A beautiful fiery bird, he tells her,
   ( 4 ) magical but untamed. "Daddy, shush, there is no such thing,"

      AndQuery        
 .       _loc.  
  ,      ,   
  .

                                                             ++   907

   void AndQuery::eval()
   {
      //     
      _lop->eval();
      _rop->eval();
        
      //  
      vector< location, allocator >::const_iterator
         riter = _rop->locations()->begin(),
         liter = _lop->locations()->begin(),
         riter_end = _rop->locations()->end(),
         liter_end = _lop->locations()->end();
        
      //  ,    
      while ( liter != liter_end &&  riter != riter_end )
      {
         //       ,   
         while ( (*liter).first > (*riter).first )
         {
            ++riter;
            if ( riter == riter_end ) return;
         }
         
         //       ,   
         while ( (*liter).first < (*riter).first )
         {
            //      
            //        
            // _max_col     
            if ( ((*liter).first == (*riter).first-1 ) &&
                 ((*riter).second == 0 ) &&
                 ((*liter).second == (*_max_col)[ (*liter).first ] ))
            {
               _loc.push_back( *liter );
               _loc.push_back( *riter );
               ++riter;
               if ( riter == riter_end ) return;
            }
            ++liter;
            if ( liter == liter_end ) return;
         }
           
         //        
         while ( (*liter).first == (*riter).first )
         {
           if ( (*liter).second+1 == ((*riter).second) )
           { //  
              _loc.push_back( *liter ); ++liter;
              _loc.push_back( *riter ); ++riter;
           }
           else
              if ( (*liter).second <= (*riter).second )
                ++liter;
              else ++riter;
              if ( liter == liter_end || riter == riter_end )
                return;
         }
      }
   }

                                                      ++   908

         AndQuery,    
      :

   ==> fiery && bird
   fiery ( 1 ) lines match
   display_location vector:
     first: 2 second: 2
     first: 2 second: 8

   bird ( 1 ) lines match
   display_location vector:
      first: 2 second: 3
      first: 2 second: 9
   fiery && bird ( 1 ) lines match
   display_location vector:
      first: 2 second: 2
      first: 2 second: 3
      first: 2 second: 8
      first: 2 second: 9

   Requested query: fiery && bird

       ,   ,   .
    ,    :

   ==> fiery && ( bird || untamed )
   fiery ( 1 ) lines match
   display_location vector:
      first: 2 second: 3
      first: 2 second: 8
   bird ( 1 ) lines match
   display_location vector:
      first: 2 second: 3
      first: 2 second: 9
   untamed ( 1 ) lines match
   display_location vector:
      first: 3 second: 2

   ( bird || untamed ) ( 2 ) lines match
   display_location vector:
      first: 2 second: 3
      first: 2 second: 9
      first: 3 second: 2

   fiery && ( bird || untamed ) ( 1 ) lines match
   display_location vector:
      first: 2 second: 2
      first: 2 second: 3
      first: 2 second: 8
      first: 2 second: 9
   Requested query: fiery && ( bird || untamed )
   ( 3 ) like a fiery bird in flight. A beautiful fiery bird, he tells her,


                        17.5.7.    new

           ,    
  :

   NotQuery *pnq;
   //  pnq ...
   //  new 
   //   NotQuery ...
   NotQuery *pnq2 = new NotQuery( *pnq );

                                                             ++   909

             Query,   
    :

   const Query *pq = pnq->op();
   //    pq?

          new,   
 ,      .  ,
 : new   -,   
       (.  15.8).
      new   ,    ,
         ,  clone():

   class Query {
   public:
      virtual Query *clone() = 0;
      // ...
   };

           NameQuery:

   class NameQuery : public Query {
   public:
      virtual Query *clone()
      //     NameQuery
      { return new NameQuery( *this ); }
      // ...
   };

     ,     Query*:

   Query *pq = new NameQuery( "valery" );
   Query *pq2 = pq->clone();

        NameQuery*,     

   Query*    NameQuery*:
   NameQuery *pnq = new NameQuery( "Rilke" );
   NameQuery *pnq2 =
   static_cast<NameQuery*>( pnq->clone() );

   (,     ,    19.1.1.)

                                                                  ++   910

    ,  ,     
 ,    ,     .
,     ,   
.         
  (      ),     
  ,        
   (      ):

   class NameQuery : public Query {
   public:
      virtual NameQuery *clone()
      { return new NameQuery( *this ); }
      // ...
   };

    pq2  pnq2      :

   // Query *pq = new NameQuery( "Broch" );
   Query *pq2 = pq->clone(); // 
   // NameQuery *pnq = new NameQuery( "Rilke" );
   NameQuery *pnq2 = pnq->clone(); // 

      clone()   NotQuery:

   class NotQuery : public Query {
   public:
      virtual NotQuery *clone()
      { return new NotQuery( *this ); }
      // ...
   };

     AndQuery  OrQuery .    clone() 
,   NotQuery, AndQuery  OrQuery    
 . (     17.6.)

          17.5.8.  ,   

        17.4,      
 ,    . ,   
 NameQuery

   NameQuery poet( "Orlen" );

    Query,   NameQuery.

                                                              ++   911

        Query  , 
 NameQuery,  .  , poet    
 NameQuery,    .
     ,      
 ,      ,   
 ?      ?   
    ,      ,  
. ,     .
      ,       
 ,    .  ,  
        .
           ,   
.      ,    , 
:  ,    ,  ,   .

                                  17.12

      NameQuery       
,   ,    . 
    ,        , 
   .  AndQuery, OrQuery  NotQuery 
        .
        ,   
   .      
NameQuery,     .   ,   
      Query      
 AndQuery, OrQuery  NotQuery ,    NameQuery  ?
(,        Query , ,
    delete   !)

                                  17.13

        :

   class AbstractObject {
   public:
      ~AbstractObject();
      virtual void doit() = 0;
      // ...
   };

                                   17.14

     :

   Query *pq = &nq;

     

   NameQuery nq( "Sneezy" );
   Query q( nq );

                                                           ++   912

   pq->eval();

  eval()   NameQuery,   

   q.eval();

  Query?

                                        17.15

           Derived :

   (a) Base* Base::copy( Base* );
       void Derived::eval();
   (b) Base* Base::copy( Base* );
       Base* Derived::copy( Derived* );
   (c) ostream& Base::print( int, ostream&=cout );
       Derived* Derived::copy( Vase* );
   (d) void Base::eval() const;
       ostream& Derived::print( int, ostream& );

                               17.16

   ,            ,
    .      
  .      Query 
 debug(),      .
     :   ,
  debug(),     . ( 
        .)

                                   17.17

        :

                                                                  ++   913

   class Object {
   public:
      virtual void doit() = 0;
      // ...
   protected:
      virtual ~Object();
   };

   class MyObject : public Object {
   public:
      MyObject( string isA );
      string isA() const;
   protected:
      string _isA;
   };


                 17.6.     A

          ,  
 (.  14.6)    (.  14.7) 
   .     
.
            . ,
      Query  .
       Query    :

   class Query {
   public: // ...
   protected:
      int _paren;
      set<short> *_solition;
      vector<location> _loc;
      // ...
   };

    _solution,   ,  ,    
  - _vec2set().  Query   _solution
 delete.
    Query      ,   
  . (   ,  
14.6.)   ,       
.
     NameQuery  -  string   
Query.    folk  NameQuery:

   NameQuery folk( "folk" );

  music   folk

                                                              ++   914

   NameQuery music = folk;

 :

  1.  ,    NameQuery   . (
     .       .)
  2.   ,    NameQuery  
     . (,     Query.)
  3.  ,     Query  
     . (,      
     .)
  4.  ,    Query   . (.)
  5.      Query    .
     (      , , , _paren 
     _solution,    music    
      folk.   , , , _loc,    
       1.   vector   , 
        music._loc   folk._loc.)
  6.      NameQuery   
          string,    
     .      music._name  
     folk._name.

      music   folk .    
,  :       _solution,
 ,  ,  .     
     Query. , ,
   :

   Query::Query( const Query &rhs )
      : _loc( rhs._loc ), _paren(rhs._paren)
   {
      if ( rhs._solution )
      {
         _solution = new set<short>;
         set<short>::iterator
            it = rhs._solution->begin(),
            end_it = rhs._solution->end();
         
         for ( ; _ir != end_it; ++it )
            _solution->insert( *it );
      }
      else _solution = 0;
   }

   ,         
,     .   
     .   
 _solution :

                                                             ++   915

   Query::Query( const Query &rhs )
      : _loc( rhs._loc ),
        _paren(rhs._paren), _solution( 0 )
   {}

    1  2  musi c  folk  ,   .    3
 ,    Query     
 .  4  5 ,   6 ,   .
        music   folk . 
    NameQuery  .
      NotQuery    Query   _op
 Query*,    ,   .  NotQuery
     delete.
     NotQuery      _op ,
    .    
  clone(),      .

   inline NotQuery::NotQuery( const NotQuery &rhs )
   //  Query::Query( const Query &rhs )
      : Query( rhs )
   { _op = rhs._op->clone(); }

         NotQuery  
 :

  1.  ,    NotQuery   .
     , .
  2.      .

     .        
      NotQuery. (
AndQuery  OrQuery   NotQuery,      
  .)
       .   
  ,      
   .     
  .
      ,       
    ,   
         .
          .   
  ,         
      .    
 ,       ,  
 .         -
    .

                                                           ++   916

            Query. 
 ,        ,
    :

   Query& Query::operator=( const Query &rhs )
   {
      //    
      if ( &rhs != this )
      {
         _paren = rhs._paren;
         _loc = rhs._loc;
         delete _solution;
         _solution = 0;
      }
      return *this;
   }

     NameQuery      . 
  NameQuery     :

  1.    Query   NameQuery  
         Query.
  2.    string    
       .

     NameQuery      .
    NotQuery, AndQuery  OrQuery   
     .    
NotQuery:

   inline NotQuery& NotQuery::operator=( const NotQuery &rhs )
   {
      //    
      if ( &rhs != this )
      {
         //     Query
         this->Query::operator=( rhs );
         //  
         _op = rhs._op->clone();
      }
      return *this;
   }

       ,     
 ,       .
     :  ,
 ,    ,    :

                                                       ++   917

   (*static_cast<Query*>(this)) = rhs;

(      AndQuery  OrQuery
  ,       .)
          . 
   ,    .

   #include "Query.h"

   int main()
   {
      NameQuery nm( "alice" );
      NameQuery nm( "emma" );

      NotQuery nq1( &nm );
      cout << "notQuery 1: " << nq1 << endl;

      NotQuery nq2( nq1 );
      cout << "notQuery 2: " << nq2 << endl;
      NotQuery nq3( &nm2 );
      cout << "notQuery 3: " << nq3 << endl;

      nq3 = nq2;
      cout << "notQuery 3   nq2: " << nq3 << endl;

      AndQuery aq( &nq1, &nm2 );
      cout << "AndQuery : " << aq << endl;

      AndQuery aq2( aq );
      cout << "AndQuery 2: " << aq2 << endl;

      AndQuery aq3( &nm, &nm2 );
      cout << "AndQuery 3: " << aq3 << endl;

      aq2 = aq3;
      cout << "AndQuery 2  : " << aq2 << endl;
   }

         :

   notQuery 1: ! alice
   notQuery 2: ! alice
   notQuery 3: ! emma
   notQuery 3   nq2: ! alice
   AndQuery : ! alice && emma
   AndQuery 2: ! alice && emma
   AndQuery 3: alice && emma
   AndQuery 2  : alice && emma

                          17.18

        AndQuery  OrQuery.

                           17.19

         AndQuery  OrQuery.

                           17.20

                                                           ++   918

           
  ?


                        17.7.   UserQuery

       :

   fiery && ( bird || potato )

           :

   AndQuery
     NameQuery( "fiery" )
     OrQuery
        NameQuery( "bird" )
        NameQuery( "potato" )

       ?      
  .       
       ,    
 .        switch 
,    eval_query().     
          :

                                                             ++   919

   vector<string>::iterator it = _query->begin(),
                            end_it = _query->end();

   for ( ; it != end_it; ++it )
     switch( evalQueryString( *it ))
     {
        case WORD:
           evalWord( *it );
           break;
        case AND:
           evalAnd();
           break;
        case OR:
           evalOr();
           break;
        case NOT:
          evalNot();
          break;
        case LPAREN:
          ++_paren;
          ++_lparenOn;
          break;
       case RPAREN:
         --_paren;
         ++_rparenOn;
         evalRParen();
         break;
   }

     eval: evalWord(), evalAnd(), evalOr(), evalNot  evalRParen()  
     Query.       ,
   .
           ,   
   6     .  
   Query    , 
  .     ( 
)   .
     6.14    TextQuery,     ,
   6.     UserQuery,  
.
           ,   
.       Query*   
,   eval_query().       :

   _paren       (
         );
   _lparenOn  _rparenOn      ,
           ( ,  
    ,     print()  17.5.1).

                                                             ++   920

      ,    .   :

   fiery || untamed

            OrQuery:

   OrQuery
      NameQuery( "fiery" )
      NameQuery( "untamed" )

          .  
  NameQuery,  OrQuery ,     ,  
.   ,     
NameQuery.
     -   ,  
.     NameQuery.      
( OrQuery),   NameQuery       OrQuery 
  .
    OrQuery :      .     
   ,      .
          ,   NameQuery.  OrQuery
    :   .  
  : _query_stack   , 
    (    NameQuery),
         .
         , 
,    _current_op.      OrQuery.
     NameQuery  ,    OrQuery
  _current_op     NameQuery    . 
 OrQuery         _query_stack.
       ,   _current_op ,   
_query_stack   ,    
 .       OrQuery.
  .        NotQuery:

   ! daddy

       .     _query_stack
   NotQuery:

                                                              ++   921

   evalNot() : incomplete!
      push on _current_op ( size == 1 )
   evalWord() : daddy
      pop _current_op : NotQuery
      add operand: WordQuery : NotQuery complete!
      push NotQuery on _query_stack

   ,      eval, ,  
.
          OrQuery    . 
       _query_stack:

   ==> fiery || untamed || shyly

   evalWord() : fiery
     push word on _query_stack
   evalOr() : incomplete!
     pop _query_stack : fiery
     add operand : WordQuery : OrQuery incomplete!
     push OrQuery on _current_op ( size == 1 )
   evalWord() : untamed
      pop _current_op : OrQuery
      add operand : WordQuery : OrQuery complete!
      push OrQuery on _query_stack
   evalOr() : incomplete!
      pop _query_stack : OrQuery
      add operand : OrQuery : OrQuery incomplete!
      push OrQuery on _current_op ( size == 1 )
      evalWord() : shyly
      pop _current_op : OrQuery
      add operand : WordQuery : OrQuery complete!
      push OrQuery on _query_stack

            
  :

   ==> fiery && ( bird || untamed )

   evalWord() : fiery
      push word on _query_stack
      evalAnd() : incomplete!
      pop _query_stack : fiery
      add operand : WordQuery : AndQuery incomplete!
      push AndQuery on _current_op ( size == 1 )
   evalWord() : bird
      _paren is set to 1
      push word on _query_stack
   evalOr() : incomplete!
      pop _query_stack : bird
      add operand : WordQuery : OrQuery incomplete!
      push OrQuery on _current_op ( size == 2 )
    evalWord() : untamed
       pop _current_op : OrQuery
       add operand : WordQuery : OrQuery complete!
       push OrQuery on _query_stack
   evalRParen() :
      _paren: 0 _current_op.size(): 1
      pop _query_stack : OrQuery
      pop _current_op : AndQuery
      add operand : OrQuery : AndQuery complete!
      push AndQuery on _query_stack

          :

   ++   922

    TextQuery,     (   
     16.4).     ;
   -  Query    
      ;
    UserQuery,       
      Query.

           
           . , 
,   Query    
 ,   UserQuery:

    AndQuery, OrQuery  NotQuery ,   
        .    
        ;
           AndQuery,
    OrQuery  NotQuery.  ,     . 
         Query*,   
    _current_op.       :  
    (NotQuery)   (AndQuery  OrQuery)   .  
     Query    .

   ,      ,   
       . 
,    ,   .     ,
  ,          
   .          ,
      , 
    .
             Query, 
,     .    ,    ,
  ,      
- add_op()       (
,   ,  ,    evalRParen() 
evalWord()).

                   17.7.1.   UserQuery

     UserQuery      ,
  ,       , 
 - query().      
 .     Query 
 eval_query():

                                                              ++   923

   //  ,    
   UserQuery user_query;
   string text;
   vector<string> query_text;
   //   
   do {
      while( cin >> text )
         query_text.push_back( text );

         //    UserQuery
         user_query.query( &query_text );

         //     
         //   Query*
         Query *query = user_query.eval_query();
      }
   while ( /*     */ );

       UserQuery:

                                                           ++   924

   #ifndef USER_QUERY_H
   #define USER_QUERY_H

   #include <string>
   #include <vector>
   #include <map>
   #include <stack>

   typedef pair<short,short> location;
   typedef vector<location,allocator> loc;

   #include "Query.h"

   class UserQuery {
   public:
      UserQuery( vector< string,allocator > *pquery = 0 )
         : _query( pquery ), _eval( 0 ), _paren( 0 ) {}
      Query *eval_query(); //  
      void query( vector< string,allocator > *pq );
      void displayQuery();
      static void word_map( map<string,loc*,less<string>,allocator> *pwm ) {
        if ( !_word_map ) _word_map = pwm;
      }
   private:
      enum QueryType { WORD = 1, AND, OR, NOT, RPAREN, LPAREN };
      QueryType evalQueryString( const string &query );
      void evalWord( const string &query );
      void evalAnd();
      void evalOr();
      void evalNot();
      void evalRParen();
      bool integrity_check();
      int _paren;
      Query *_eval;
      vector<string> *_query;
      stack<Query*, vector<Query*> > _query_stack;
      stack<Query*, vector<Query*> > _current_op;
      static short _lparenOn, _rparenOn;
      static map<string,loc*,less<string>,allocator> *_word_map;
   };

   #endif

    ,         
 Query,    .     
,     ,  
 (  )       (, 
    clone())   ,  
 .      ,  
,       .
         eval.  evalAnd()
 evalOr()   .     

                                                             ++   925

_query_stack (,    stack,   
,    : top()     pop() 
   ).         AndQuery
 OrQuery,      ,   . 
   AndQuery  OrQuery     ,
     .    
   _current_op:

   inline void UserQuery::evalAnd()
   {
      Query *pop = _query_stack.top(); _query_stack.pop();
      AndQuery *pq = new AndQuery( pop );

      if ( _lparenOn )
      { pq->lparen( _lparenOn ); _lparenOn = 0; }

      if ( _rparenOn )
      { pq->rparen( _rparenOn ); _rparenOn = 0; }

      _current_op.push( pq );
   }

   inline void UserQuery::evalOr()
   {
      Query *pop = _query_stack.top(); _query_stack.pop();
      OrQuery *pq = new OrQuery( pop );

      if ( _lparenOn )
      { pq->lparen( _lparenOn ); _lparenOn = 0; }

      if ( _rparenOn )
      { pq->rparen( _rparenOn ); _rparenOn = 0; }

      _current_op.push( pq );
   }

    evalNot()   .     
 NotQuery,         
 .       _current_op:

   inline void UserQuery::evalNot()
   {
      NotQuery *pq = new NotQuery;

      if ( _lparenOn )
      { pq->lparen( _lparenOn ); _lparenOn = 0; }

      if ( _rparenOn )
      { pq->rparen( _rparenOn ); _rparenOn = 0; }

      _current_op.push( pq );
   }

                                                          ++   926

         evalRParen().  
        _current_op,   
.      .  
_query_stack        ,  
 _current_op    .   
add_op()  Query,   .     
  _query_stack:

   inline void UserQuery::evalRParen()
   {
      if ( _paren < _current_op.size() )
      {
         Query *poperand = _query_stack.top();
         _query_stack.pop();

         Query *pop = _current_op.top();
         _current_op.pop();
         pop->add_op( poperand );
         _query_stack.push( pop );
   }

    evalWord()   .     
 _word_map       .   ,
           
   NameQuery.       
   .      _current_op 
     ,    , 
  NameQuery,       _query_stack.
   _current_op   ,    
  add_op()   NameQuery,   
     _query_stack:

                                                            ++   927

   inline void UserQuery::evalWord( const string &query )
   {
      NameQuery *pq;
      loc *ploc;

      if ( ! _word_map->count( query ))
         pq = new NameQuery( query );
      else {
         ploc = ( *_word_map )[ query ];
         pq = new NameQuery( query, *ploc );
      }

      if ( _current_op.size() <= _paren )
         _query_stack.push( pq );
      else {
         Query *pop = _current_op.top();
         _current_op.pop();
         pop->add_op( pq );
         _query_stack.push( pop );
     }
   }

                                 17.21

    ,      
  UserQuery.

                                  17.22

     print()   UserQuery.    ,  
.

                                17.8.   

    main()       
:

   #include "TextQuery.h"

   int main()
   {
      TextQuery tq;
      tq.build_up_text();
      tq.query_text();
   }

   - build_text_map()     ,   
doit()   6.14:

                                                         ++   928

   inline void TextQuery::build_text_map()
   {
      retrieve_text();
      separate_words();
      filter_text();
      suffix_text();
      strip_caps();
      build_word_map();
   }

   - query_text()      6.14. 
          
 .     query_text()  ,    -
19:

   19       FTP-  Addison-
      Wesley  ,     .

                                                            ++   929

   void TextQuery::query_text()
   {
      /*  :
       *
       * text:    
       * query_text:     
       * caps:    
       *    
       *
       * user_query:  UserQuery,   
       *     
       */

       string text;
       string caps( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
       vector<string, allocator> query_text;
       UserQuery user_query;

       //    UserQuery
       NotQuery::all_locs( text_locations->second );
       AndQuery::max_col( &line_cnt );
       UserQuery::word_map( word_map );

       do {
         //   ,   
         query_text.clear();
         cout << " . ,    "
              << " .\n"
              << " (  )   ( . ).\n\n"
              << "==> ";

       /*
        *     ,
        *    ,  
        *    query_text ...
        *
        * :     
        *  ,     ...
        */

      while( cin >> text )
      {
         if ( text == "." )
            break;

         string::size_type pos = 0;
         while (( pos = text.find_first_of( caps, pos ))
                  != string::npos )
            text[pos] = tolower( text[pos] );
            query_text.push_back( text );
         }

         //       
         //   ...
         if ( ! query_text.empty() )
         {
            //    UserQuery
            user_query.query( &query_text );

            //    
            //   Query*
            //  .   17.7
            // query -    TextQuery  Query*
            query = user_query.eval_query();

            //   Query,
            //     17.7
            query->eval();

            //    
            // -  TextQuery
            display_solution();

            //     
            //  


                                                             ++   930

   }

    ,      .   
   Bartleby.     AndQuery,
       . (,  ,
    ,   .)

    . ,     .
    (  )   ( . ).
   ==> John && Jacob && Astor

      john ( 3 ) lines match
      jacob ( 3 ) lines match
      john && jacob ( 3 ) lines match
      astor ( 3 ) lines match
      john && jacob && astor ( 5 ) lines match

   Requested query: john && jacob && astor
   ( 34 ) All who know me consider me an eminently /safe/ man. The late
   John Jacob
   ( 35 ) Astor, a personage little given to poethic enthusiasm, had no
   hesitation in
   ( 38 ) my profession by the late John Jacob Astor, a name which, I admit
   I love to
   ( 40 ) bullion. I will freely add that I was not insensible to the late
   John Jacob
   ( 41 ) Astor's good opinion.

    ,       ,  
  Heart of Darkness  :

   ==> horror || ( absurd && mystery ) || ( North && Pole )

      horror ( 5 ) lines match
      absurd ( 8 ) lines match
      mystery ( 12 ) lines match
      ( absurd && mystery ) ( 1 ) lines match
      horror || ( absurd && mystery ) ( 6 ) lines match
      north ( 2 ) lines match
      pole ( 7 ) lines match
      ( north && pole ) ( 1 ) lines match
      horror || ( absurd && mystery ) || ( north && pole )
      ( 7 ) lines match

   Requested query: horror || ( absurd && mystery ) || ( north && pole )
   ( 257 ) up I will go there.' The North Pole was one of these
   ( 952 ) horros. The heavy pole had skinned his poor nose
   ( 3055 ) some lightless region of subtle horrors, where pure,
   ( 3673 ) " 'The horror! The horror!'
   ( 3913 ) the whispered cry, 'The horror! The horror! '
   ( 3957 ) absurd mysteries not fit for a human being to behold.
   ( 4088 ) wind. 'The horror! The horror!'

             Portrait of a Lady.
          :

   ==> clever && trick || devious

      clever ( 46 ) lines match
      trick ( 12 ) lines match
      clever && trick ( 2 ) lines match
      devious ( 1 ) lines match
      clever && trick || devious ( 3 ) lines match

   Requested query: clever && trick || devious
   ( 13914 ) clever trick she had guessed. Isabel, as she herself grew older

                                                                  ++   931

   ( 13935 ) lost the desire to know this lady's clever trick. If she had
   ( 14974 ) desultory, so devious, so much the reverse of processional.
   There were

                                   17.23

          :  
       ,   , 
  (.  6.9  6.10). , ,   
 maps, ,        map,
        
 .   query_text() ,   
    .

                                  17.24

        ,    
 Ȕ,    InclusiveAndQuery     &.
    ,      
,    . , 

   We were her pride of ten, she named us

 :

   pride & ten

 :

   pride && ten

     InclusiveAndQuery.

                                 17.25

       display_solution()   
  .       
  ostream,     . 
display_solution() ,  ostream   .   
     UserQuery?

                                                             ++   932

   void TextQuery::display_solution()
   {
      cout << "\n"
           << "Requested query: "
           << *query << "\n\n";

      const set<short,less<short>,allocator> *solution = query-
      >solution();

      if ( ! solution->size() ) {
         cout << "\n\t"
              << "Sorry, no matching lines were found in text.\n"
              << endl;
      }

      set<short>::const_iterator it = solution->begin(),
                                 end_it = solution->end();

      for ( ; it != end_it; ++it ) {
         int line = *it;
         //    1 ...
         cout << "( " << line+1 << " ) "
              << (*lines_of_text)[line] << '\n';
      }
      cout << endl;
   }

                              17.26

     TextQuery     , 
   .

   (a)        .
   (b)       -.
   (c)        (.    7.8).

                             17.27

           
  :

   (a)  ,     AndQuery  
        ,  Motion Picture Screen Cartoonists.
   (b)             ,  
       .
   (c)    ,      
            , ,    
       .
   (d)          ,
              
           :

    ==> John && Jacob && Astor

                                                                 ++   933

      (1) john ( 3 ) lines match
      (2) jacob ( 3 ) lines match
      (3) john && jacob ( 3 ) lines match
      (4) astor ( 3 ) lines match
      (5) john && jacob && astor ( 5 ) lines match

      //  :   ,   
      //   

     ==> ? 3

    //   ,   
    //    Enter   ,
    //          
    !  (Enter  ,      )
    1-3
