Esempio n. 1
0
/** Plus operator for TimeSplitterType.
 * Combines a filter and a splitter by removing entries that are filtered out
 *from the splitter.
 * Also, will combine two filters together by "and"ing them
 *
 * @param a :: TimeSplitterType splitter OR filter
 * @param b :: TimeSplitterType splitter OR filter.
 * @throw std::invalid_argument if two splitters are given.
 */
TimeSplitterType operator+(const TimeSplitterType &a,
                           const TimeSplitterType &b) {
  bool a_filter, b_filter;
  a_filter = isFilter(a);
  b_filter = isFilter(b);

  if (a_filter && b_filter) {
    return a & b;
  } else if (a_filter && !b_filter) {
    return b & a;
  } else if (!a_filter && b_filter) {
    return a & b;
  } else // (!a_filter && !b_filter)
  {
    // Both are splitters.
    throw std::invalid_argument("Cannot combine two splitters together, as the "
                                "output is undefined. Try splitting each "
                                "output workspace by b after the a split has "
                                "been done.");
  }
}
Esempio n. 2
0
void BRTKernelDef::PrintVoutPostfix(std::ostream & out) const{
   out << "    __vout_counter+=1.0f;"<<std::endl;
   FunctionType* ft = static_cast<FunctionType*>(decl->form);
   std::set<unsigned int >::iterator beginvout
      = voutFunctions[FunctionName()->name].begin();
   std::set<unsigned int >::iterator endvout
      = voutFunctions[FunctionName()->name].end();
   std::set<unsigned int >::iterator iter;
   std::set<unsigned int >::iterator inneriter;
   bool limited_vout=false;
   bool allone=true;
   unsigned int limited_vout_counter=0;
   unsigned int numlimits=0;
   for (iter = beginvout;iter!=endvout;++iter) {
      Decl * decl = ft->args[*iter];
      Expression * vout_limit = decl->form->getQualifiers().vout;
      if (vout_limit) {
        bool filter=isFilter(vout_limit);
        allone=(allone&&filter);
        
        if (limited_vout||beginvout==iter) {
          limited_vout=true;
          numlimits++;
        }
        else
          limited_vout=false;
      }
   }
   if (numlimits>1&&!allone){
     numlimits=0;
     limited_vout=false;
   }
   for (iter = beginvout;iter!=endvout;++iter) {
      Decl * decl = ft->args[*iter];
      Expression * vout_limit = decl->form->getQualifiers().vout;
      
      if (vout_limit&&limited_vout) {
        if (limited_vout_counter==0) out << "     if (";
        bool useparen=(vout_limit->precedence() < 
                       RelExpr(RO_Less,
                               NULL,
                               NULL,
                               vout_limit->location).precedence());
        // the above is a simple check for the common expressions.
        // no need to get fancy here for parens are ok in this case.
        out <<"(__vout_counter >= ";
        if (useparen) out << "(";
        vout_limit->print(out);
        if (useparen) out << ")";
        out << ")";
        limited_vout_counter++;
        if (limited_vout_counter==numlimits) {
           out <<") {"<<std::endl;
           for (inneriter = beginvout;inneriter!=endvout;++inneriter) {
              Decl * decl = ft->args[*inneriter];
              out <<"      ";
              out <<getDeclStream(decl,"_outputs")<<".push_back(0);"<<std::endl;
           }
           out <<"      ";              
           out <<"break;"<<std::endl;
           out <<"    }"<<std::endl;
        }else {
           out << "&&";
        }
      }else {
         out << "    "<<getDeclStream(decl,"_values")<< " = ";

         out << "(";
         out << decl->name->name<<"->getDimension()==2?";
         out << "finiteValueProduced"<<getDimensionString(2)<<undecoratedBase(decl);
         out << ":finiteValueProduced"<<getDimensionString(1);      
         out << undecoratedBase(decl)<<")(*"<<getDeclStream(decl,"_outputs");
         out << ".back())?1:0;"<<std::endl;
      }
   }
   out << "  }"<<std::endl;
   for (iter = beginvout;iter!=endvout;++iter) {
      
      Decl * decl = ft->args[*iter];
      out << "  if ("<<decl->name->name<<"->getDimension()==2) {"<<std::endl;
      PrintVoutDimensionalShift(out,decl,2);
      out << "  }else {"<<std::endl;
      PrintVoutDimensionalShift(out,decl,1);
      out << "  }"<<std::endl;
      out << "  while ("<<getDeclStream(decl,"_outputs")<<".size()) {";
      out << std::endl;
      out << "    if ("<<getDeclStream(decl,"_outputs")<<".back())"<<std::endl;
      out << "      delete "<<getDeclStream(decl,"_outputs")<<".back();";
      out << std::endl;
      out << "    "<<getDeclStream(decl,"_outputs")<<".pop_back();"<<std::endl;
      out << "  }"<<std::endl;
   }
}