1 
2 /* Web Polygraph       http://www.web-polygraph.org/
3  * Copyright 2003-2011 The Measurement Factory
4  * Licensed under the Apache License, Version 2.0 */
5 
6 #include "pgl/pgl.h"
7 
8 #include "xstd/String.h"
9 #include "pgl/PglRec.h"
10 #include "pgl/PglNumSym.h"
11 #include "pgl/PglArraySym.h"
12 #include "pgl/PglDistrSym.h"
13 #include "pgl/ObjLifeCycleSym.h"
14 
15 
16 
17 String ObjLifeCycleSym::TheType = "ObjLifeCycle";
18 
19 static String strBirthday = "birthday";
20 static String strExpires = "expires";
21 static String strLength = "length";
22 static String strTimeDistr = "time_distr";
23 static String strTimeDistrArr = "time_distr[]";
24 static String strVariance = "variance";
25 static String strWithLmt = "with_lmt";
26 
27 
ObjLifeCycleSym()28 ObjLifeCycleSym::ObjLifeCycleSym(): RecSym(TheType, new PglRec) {
29 	theRec->bAdd(strTimeDistr, strBirthday, 0);
30 	theRec->bAdd(strTimeDistr, strLength, 0);
31 	theRec->bAdd(NumSym::TheType, strVariance, 0);
32 	theRec->bAdd(NumSym::TheType, strWithLmt, 0);
33 	theRec->bAdd(strTimeDistrArr, strExpires, 0);
34 }
35 
ObjLifeCycleSym(const String & aType,PglRec * aRec)36 ObjLifeCycleSym::ObjLifeCycleSym(const String &aType, PglRec *aRec): RecSym(aType, aRec) {
37 }
38 
isA(const String & type) const39 bool ObjLifeCycleSym::isA(const String &type) const {
40 	return RecSym::isA(type) || type == TheType;
41 }
42 
dupe(const String & type) const43 SynSym *ObjLifeCycleSym::dupe(const String &type) const {
44 	if (isA(type))
45 		return new ObjLifeCycleSym(this->type(), theRec->clone());
46 	return RecSym::dupe(type);
47 }
48 
bday() const49 RndDistr *ObjLifeCycleSym::bday() const {
50 	return getDistr(strBirthday);
51 }
52 
length() const53 RndDistr *ObjLifeCycleSym::length() const {
54 	return getDistr(strLength);
55 }
56 
variance(double & ratio) const57 bool ObjLifeCycleSym::variance(double &ratio) const {
58 	return getDouble(strVariance, ratio);
59 }
60 
withLmt(double & ratio) const61 bool ObjLifeCycleSym::withLmt(double &ratio) const {
62 	return getDouble(strWithLmt, ratio);
63 }
64 
expires(Array<RndDistr * > & times,RndDistr * & selector,Array<QualifSym * > & qs) const65 bool ObjLifeCycleSym::expires(Array<RndDistr*> &times, RndDistr *&selector, Array<QualifSym*> &qs) const {
66 	SynSymTblItem *ti = 0;
67 	Assert(theRec->find(strExpires, ti));
68 	if (!ti->sym())
69 		return false; // undefined
70 
71 	ArraySym &a = (ArraySym&)ti->sym()->cast(ArraySym::TheType);
72 	selector = a.makeSelector(strExpires);
73 	for (int i = 0; i < a.count(); ++i) {
74 		DistrSym &ds = (DistrSym&)a[i]->cast(DistrSym::TheType);
75 		times.append(ds.val());
76 		qs.append(ds.qualifier());
77 	}
78 
79 	return true;
80 }
81