37 NS_FATAL_ERROR ("Invalid Random Variable specification: " << defaultValue); |
37 NS_FATAL_ERROR ("Invalid Random Variable specification: " << defaultValue); |
38 } |
38 } |
39 DefaultValueList::Add (this); |
39 DefaultValueList::Add (this); |
40 } |
40 } |
41 |
41 |
42 RandomVariable * |
42 RandomVariable |
43 RandomVariableDefaultValue::GetCopy (void) |
43 RandomVariableDefaultValue::Get (void) const |
44 { |
44 { |
45 RandomVariable *variable; |
45 RandomVariable variable; |
46 bool ok; |
46 bool ok; |
47 ok = Parse (m_value, true, &variable); |
47 ok = Parse (m_value, true, &variable); |
48 NS_ASSERT (ok); |
48 NS_ASSERT (ok); |
49 return variable; |
49 return variable; |
50 } |
50 } |
51 double |
51 double |
52 RandomVariableDefaultValue::ReadAsDouble (std::string value, bool &ok) |
52 RandomVariableDefaultValue::ReadAsDouble (std::string value, bool &ok) const |
53 { |
53 { |
54 double v; |
54 double v; |
55 std::istringstream iss; |
55 std::istringstream iss; |
56 iss.str (value); |
56 iss.str (value); |
57 iss >> v; |
57 iss >> v; |
58 ok = !iss.bad () && !iss.fail (); |
58 ok = !iss.bad () && !iss.fail (); |
59 return v; |
59 return v; |
60 } |
60 } |
61 bool |
61 bool |
62 RandomVariableDefaultValue::Parse (const std::string &value, |
62 RandomVariableDefaultValue::Parse (const std::string &value, |
63 bool mustCreate, RandomVariable **pVariable) |
63 bool mustCreate, RandomVariable *pVariable) const |
64 { |
64 { |
65 std::string::size_type pos = value.find_first_of(":"); |
65 std::string::size_type pos = value.find_first_of(":"); |
66 if (pos == std::string::npos) |
66 if (pos == std::string::npos) |
67 { |
67 { |
68 return false; |
68 return false; |
74 { |
74 { |
75 double constant = ReadAsDouble (v, ok); |
75 double constant = ReadAsDouble (v, ok); |
76 if (mustCreate) |
76 if (mustCreate) |
77 { |
77 { |
78 NS_LOG_LOGIC ("create Constant constant=" << constant); |
78 NS_LOG_LOGIC ("create Constant constant=" << constant); |
79 *pVariable = new ConstantVariable (constant); |
79 *pVariable = ConstantVariable (constant); |
80 } |
80 } |
81 else |
81 else |
82 { |
82 { |
83 NS_LOG_LOGIC ("parse Constant constant=" << constant); |
83 NS_LOG_LOGIC ("parse Constant constant=" << constant); |
84 } |
84 } |
98 minVal = ReadAsDouble (min, ok); |
98 minVal = ReadAsDouble (min, ok); |
99 maxVal = ReadAsDouble (max, ok); |
99 maxVal = ReadAsDouble (max, ok); |
100 if (mustCreate) |
100 if (mustCreate) |
101 { |
101 { |
102 NS_LOG_LOGIC ("create Uniform min=" << min << ", max=" << max); |
102 NS_LOG_LOGIC ("create Uniform min=" << min << ", max=" << max); |
103 *pVariable = new UniformVariable (minVal, maxVal); |
103 *pVariable = UniformVariable (minVal, maxVal); |
104 } |
104 } |
105 else |
105 else |
106 { |
106 { |
107 NS_LOG_LOGIC ("parse Uniform min=" << min << ", max=" << max); |
107 NS_LOG_LOGIC ("parse Uniform min=" << min << ", max=" << max); |
108 } |
108 } |