Changeset 3f6d71f in tol


Ignore:
Timestamp:
Feb 23, 2011, 9:02:59 AM (16 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
af23d24
Parents:
5430aa8
Message:

Fixes #1106
Select will show an error when the condition is unknown

Refs #1101
DeepCopy is transformed in an special function

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@3227 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/btol/set_type/setgra.cpp

    r5430aa8 r3f6d71f  
    19561956//--------------------------------------------------------------------
    19571957{
    1958     //InitTotalTime("BSetSelect::CalcContens()");
    1959     BSyntaxObject*     objCode;
    1960     BSet&              set    = Set (Arg(1));
    1961     BUserCode*   uCod   = UCode(Arg(2));
    1962     BList*           aux    = NIL;
    1963     BList*           result = NIL;
    1964     BText              error;
    1965     BCode&       cond = uCod->Contens();
    1966     BGrammar* g = cond.Grammar();
    1967     if(g!=GraReal())
    1968     {
    1969         Error(I2("The condition function for Select should return a Real "
    1970                  "object",
    1971                  "La función de condición para Select debe devolver un "
    1972      "objeto de tipo Real")+":\n"+
    1973      cond.Operator()->LexInfo());
    1974         return;
    1975     }
    1976     for(BInt n=1; n<=set.Card(); n++)
    1977     {
    1978         objCode  = cond.Evaluator(NCons(set[n]));
    1979         if(!objCode)
    1980         {
    1981             error = I2("Wrong condition definition for Select function.",
    1982                        "Condición mal definida para la función Select.");
    1983             Error(error);
    1984             break;
    1985         }
    1986         BBool valid = Real(objCode)!=0;
    1987         DESTROY(objCode);
    1988         if(valid) { LstFastAppend(result, aux, set[n]); }
    1989     }
    1990     contens_.RobElement(result);
    1991     //SumPartialTime;
     1958  //InitTotalTime("BSetSelect::CalcContens()");
     1959  BSyntaxObject* objCode;
     1960  BSet& set = Set (Arg(1));
     1961  BUserCode* uCod = UCode(Arg(2));
     1962  BList* aux = NIL;
     1963  BList* result = NIL;
     1964  BText error;
     1965  BCode& cond = uCod->Contens();
     1966  BGrammar* g = cond.Grammar();
     1967  if(g!=GraReal())
     1968  {
     1969    Error(I2("The condition function for Select should return a Real "
     1970             "object",
     1971             "La función de condición para Select debe devolver un "
     1972             "objeto de tipo Real")+":\n"+
     1973          cond.Operator()->LexInfo());
     1974    return;
     1975  }
     1976  for(BInt n=1; n<=set.Card(); n++)
     1977  {
     1978    objCode  = cond.Evaluator(NCons(set[n]));
     1979    if(!objCode)
     1980    {
     1981      error = I2("[Select] Wrong condition definition.",
     1982                 "[Select] Condición mal definida.");
     1983      Error(error);
     1984      break;
     1985    }
     1986    BDat dat = Dat(objCode);
     1987    BBool valid = dat!=0;
     1988    if(!dat.IsKnown())
     1989    {
     1990      error = I2("[Select] condition function cannot return unknown values.",
     1991                 "[Select] la función de condición no puede devolver valores desconocidos.");
     1992      Error(error);
     1993      DESTROY(objCode);
     1994      break;
     1995    }
     1996    DESTROY(objCode);
     1997    if(valid) { LstFastAppend(result, aux, set[n]); }
     1998  }
     1999  contens_.RobElement(result);
     2000  //SumPartialTime;
    19922001}
    19932002
    … …  
    22052214                         BText("No se encuentra el direcorio ")+path));
    22062215  }
    2207 }
    2208 
    2209 //--------------------------------------------------------------------
    2210 BSyntaxObject* CopyReal(BSyntaxObject* obj,const BArray<BDat>& p,BInt& pos)
    2211 {
    2212     BDat dat = Dat(obj);
    2213     if(p.Size()) { dat = p[pos++]; }
    2214     return(new BContensDat("",dat,""));
    2215 };
    2216 
    2217 //--------------------------------------------------------------------
    2218 BSyntaxObject* CopyPolyn(BSyntaxObject* obj,const BArray<BDat>& p,BInt& pos)
    2219 {
    2220     BPol pol = Pol(obj);
    2221     pol.Aggregate();
    2222     BInt j;
    2223     if(p.Size()&&((pol.Size()!=1)||(pol[0].Coef()!=0)))
    2224     {
    2225         for(j=0; j<pol.Size(); j++) { pol[j].PutCoef(p[pos++]); }
    2226     }
    2227     return(new BContensPol("",pol,""));
    2228 };
    2229 
    2230 //--------------------------------------------------------------------
    2231 BSyntaxObject* CopyRatio(BSyntaxObject* obj,const BArray<BDat>& p,BInt& pos)
    2232 {
    2233     BRat rat = Rat(obj);
    2234     BPol num = rat.Numerator  ();
    2235     BPol den = rat.Denominator();
    2236     BInt j;
    2237     if(p.Size())
    2238     {
    2239         for(j=1; j<num.Size(); j++) { num[j].PutCoef(p[pos++]); }
    2240         for(j=1; j<den.Size(); j++) { den[j].PutCoef(p[pos++]); }
    2241         rat.PutNumerator  (num);
    2242         rat.PutDenominator(den);
    2243     }
    2244     return(new BContensRat("",rat,""));
    2245 };
    2246 
    2247 //--------------------------------------------------------------------
    2248 BSyntaxObject* CopyMatrix(BSyntaxObject* obj,const BArray<BDat>& p,BInt& pos)
    2249 {
    2250     BMat mat = Mat(obj);
    2251     if(p.Size())
    2252     {
    2253         for(BInt i=0; i<mat.Rows(); i++)
    2254         {
    2255             for(BInt j=0; j<mat.Columns(); j++)
    2256             {
    2257                 mat(i,j) = p[pos++];
    2258             }
    2259         }
    2260     }
    2261     return(new BContensMat("",mat,""));
    2262 };
    2263 
    2264 //--------------------------------------------------------------------
    2265 BSyntaxObject* CopyCode(BSyntaxObject* obj)
    2266 {
    2267   BCode& cod = Code(obj);
    2268   BUserFunction* opr = (BUserFunction*)cod.Operator();
    2269   if(opr)
    2270   {
    2271     if(opr->Mode()==BBUILTINFUNMODE)
    2272     {
    2273       BCode newCod;
    2274       newCod.Replicate(Code(obj));
    2275       return(new BContensCode("",newCod,""));
    2276     }
    2277     else if(opr->Mode()==BUSERFUNMODE)
    2278     {
    2279       BUserFunction* usf = new BUserFunction("",opr->Grammar());
    2280       BUserFunCode* result = usf->GetCode();
    2281       usf->PutName(opr->Name());
    2282       usf->PutDescription(opr->Description());
    2283       usf->SetExpression(opr->Declaration(), opr->Definition());
    2284       result->PutName(opr->Name());
    2285       result->PutDescription(opr->Description());
    2286       return(result);
    2287     }
    2288   }
    2289   else
    2290   {
    2291     Error(BText("Cannot copy Code ")<<obj->Identify());
    2292     return(NULL);
    2293   }
    2294 };
    2295 /*
    2296 //--------------------------------------------------------------------
    2297 BSyntaxObject* CopyNameBlock(BSyntaxObject* obj,const BArray<BDat>& p,BInt& pos)
    2298 {
    2299   BUseerNameBlock* unb = (BUseerNameBlock*)obj
    2300   BNameBlock mat = unb->Contens();
    2301   if(p.Size())
    2302   {
    2303           for(BInt i=0; i<mat.Rows(); i++)
    2304           {
    2305             for(BInt j=0; j<mat.Columns(); j++)
    2306             {
    2307                 mat(i,j) = p[pos++];
    2308             }
    2309         }
    2310     }
    2311     return(new BContensMat("",mat,""));
    2312 };
    2313 */
    2314 
    2315 //--------------------------------------------------------------------
    2316 BSyntaxObject* CopySet(BSyntaxObject* obj,const BArray<BDat>& p,BInt& pos);
    2317 
    2318 //--------------------------------------------------------------------
    2319 void DeepCopy(const BSet& sample,BSet& copy,const BArray<BDat>& p,BInt& pos)
    2320 {
    2321   BList* lst = NIL;
    2322   BList* aux = NIL;
    2323   BInt i;
    2324   for(i=1; i<=sample.Card(); i++)
    2325   {
    2326     if(sample[i])
    2327     {
    2328       BSyntaxObject* obj = NIL;
    2329       BGrammar*      gra = sample[i]->Grammar();
    2330            if(gra==GraReal   ()) { obj = CopyReal   (sample[i],p,pos); }
    2331       else if(gra==GraPolyn  ()) { obj = CopyPolyn  (sample[i],p,pos); }
    2332       else if(gra==GraRatio  ()) { obj = CopyRatio  (sample[i],p,pos); }
    2333       else if(gra==GraMatrix ()) { obj = CopyMatrix (sample[i],p,pos); }
    2334       else if(gra==GraSet    ()) { obj = CopySet    (sample[i],p,pos); }
    2335       else if(gra==GraCode   ()) { obj = CopyCode   (sample[i]);       }
    2336       else                                 { obj = sample[i]->CopyContens ();    }
    2337       if(obj && !obj->HasName())
    2338       {
    2339         obj->PutName(sample[i]->Name());
    2340       }
    2341       LstFastAppend(lst,aux,obj);
    2342     }
    2343   }
    2344   copy.RobStruct(lst,sample.Struct(),sample.SubType());
    2345   if(sample.HasIndexByName())
    2346   {
    2347     copy.SetIndexByName();
    2348   }
    2349 };
    2350 
    2351 
    2352 //--------------------------------------------------------------------
    2353 BSyntaxObject* CopySet(BSyntaxObject* obj,const BArray<BDat>& p,BInt& pos)
    2354 {
    2355     BSet& set = Set(obj);
    2356     BSet        copy;
    2357     DeepCopy(set,copy,p,pos);
    2358     copy.PutSubType(set.SubType());
    2359     copy.PutStruct(set.Struct());
    2360     return(new BContensSet("",copy,""));
    2361 };
    2362 
    2363 
    2364 //--------------------------------------------------------------------
    2365 DeclareContensClass(BSet, BSetTemporary, BSetDeepCopy);
    2366 DefExtOpr(1, BSetDeepCopy, "DeepCopy", 1, 2, "Set Matrix",
    2367           I2("(Set sample [, Matrix matrix])",
    2368              "(Set ejemplo [, Matrix matriz])"),
    2369           I2("Builds a set of a given example,substituting optionaly number dates "
    2370              "from matrix dates.The argument must be a row matrix with so dates "
    2371              "as number dates in example set",
    2372              "Construye un conjunto semejante al ejemplo dado en el que "
    2373              ", opcionalmente, se sustituyen los datos numéricos por los datos de "
    2374              "la matriz dada.El argumento matriz debe ser una matriz fila con tantos "
    2375              "datos como datos numericos haya en el conjunto ejemplo"
    2376               ),
    2377           BOperClassify::Conversion_);
    2378 
    2379 //--------------------------------------------------------------------
    2380 void BSetDeepCopy::CalcContens()
    2381 //--------------------------------------------------------------------
    2382 {
    2383     BSet& S = Set(Arg(1));
    2384     BArray<BDat> p;
    2385     BInt pos = -1;
    2386     if(Arg(2))
    2387     {
    2388         BMat M = Mat(Arg(2));
    2389         p       = M.Data();
    2390         pos = 0;
    2391     }
    2392     DeepCopy(S,contens_,p,pos);
    23932216}
    23942217
Note: See TracChangeset for help on using the changeset viewer.