home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / 5-22.C < prev    next >
Text File  |  1991-12-04  |  1KB  |  37 lines

  1. /* Copyright (c) 1992 by AT&T Bell Laboratories. */
  2. /* Advanced C++ Programming Styles and Idioms */
  3. /* James O. Coplien */
  4. /* All rights reserved. */
  5.  
  6. Value *
  7. BPF::evaluate(Value *input = 0) {
  8.     Value *f = cachedInput->evaluate(input);
  9.     if (f->f1() > f1() && f->f1() < f2()) return f;
  10.     else return zero;
  11. }
  12.  
  13. Value *
  14. BPF::operator()(Value* f) {
  15.     switch(f->type()) {
  16.     case T_LPF:
  17.         if (f->f1() > f2()) return this;
  18.         else return new BPF(f1(), f->f1());
  19.     case T_HPF:
  20.         if (f->f1() < f1()) return this;
  21.         else return new BPF(f->f1(), f2());
  22.     case T_BPF:
  23.         Frequency lowfreq = f->f1();
  24.         Frequency highfreq = ((Filter*)f)->f2();
  25.         if (f1() > lowfreq) lowfreq = f1();
  26.         if (f2() < highfreq) highfreq = f2();
  27.         return new BPF(lowfreq, highfreq);
  28.     case T_Notch:
  29.         cachedInput = f;
  30.         return this;
  31.     case T_Data:
  32.         myType = T_Data;
  33.         cachedInput = f;
  34.         return evaluate();
  35.     }
  36. }
  37.