38 using lsst::daf::base::PropertySet;
39 using lsst::daf::base::Persistable;
47 _myos =
new std::ostringstream();
58 : _myos(new
std::ofstream(file.c_str(), append ?
std::ios_base::app
59 :
std::ios_base::trunc)),
62 _myos->exceptions(std::ofstream::failbit | std::ofstream::badbit);
67 if (_myos)
delete _myos;
75 std::ostringstream *ss =
dynamic_cast<std::ostringstream*
>(_os);
76 if (ss)
return ss->str();
85 std::ofstream *
fs =
dynamic_cast<std::ofstream*
>(_os);
96 (*_os) <<
"#<?cfg paf policy ?>" << std::endl;
99 Policy::StringArray::const_iterator ni;
100 for(ni=names.begin(); ni != names.end(); ++ni) {
102 const std::type_info& tp = policy.typeOf(*ni);
103 if (tp ==
typeid(
bool)) {
104 writeBools(*ni, policy.getBoolArray(*ni));
106 else if (tp ==
typeid(
int)) {
107 writeInts(*ni, policy.getIntArray(*ni));
109 else if (tp ==
typeid(
double)) {
110 writeDoubles(*ni, policy.getDoubleArray(*ni));
112 else if (tp ==
typeid(std::string)) {
113 writeStrings(*ni, policy.getStringArray(*ni));
115 else if (tp ==
typeid(PropertySet::Ptr)) {
116 writePolicies(*ni, policy.getPolicyArray(*ni));
118 else if (tp ==
typeid(Persistable::Ptr)) {
119 writeFiles(*ni, policy.getFileArray(*ni));
122 throw LSST_EXCEPT(pexExcept::LogicError,
"Policy: unexpected type for name=" + *ni);
125 catch (NameNotFound&) {
127 writeString(*ni,
"<missing data>");
134 std::vector<bool> vals;
135 vals.push_back(value);
136 writeBools(name, vals);
140 std::vector<int> vals;
141 vals.push_back(value);
142 writeInts(name, vals);
146 std::vector<double> vals;
147 vals.push_back(value);
148 writeDoubles(name, vals);
152 const std::string& value)
154 std::vector<std::string> vals;
155 vals.push_back(value);
156 writeStrings(name, vals);
160 std::vector<Policy::Ptr> vals;
162 writePolicies(name, vals);
166 const PolicyFile& value)
168 std::vector<Policy::FilePtr> vals;
170 writeFiles(name, vals);
virtual void writeBool(const std::string &name, bool value)
write the given property out as policy data
std::shared_ptr< PolicyFile > FilePtr
std::shared_ptr< Policy > Ptr
std::string toString()
return the written data as a string.
definition of the PolicyFile class
virtual ~PolicyWriter()
delete this writer
void close()
close the output stream.
the definition of the PolicyWriter class
virtual void write(const Policy &policy, bool doDecl=false)
write the contents of a policy the attached stream.
std::vector< std::string > StringArray
virtual void writeFile(const std::string &name, const PolicyFile &value)
write the given property out as policy data
virtual void writeString(const std::string &name, const std::string &value)
write the given property out as policy data
virtual void writeDouble(const std::string &name, double value)
write the given property out as policy data
virtual void writeInt(const std::string &name, int value)
write the given property out as policy data
virtual void writePolicy(const std::string &name, const Policy &value)
write the given property out as policy data
PolicyWriter(std::ostream *out=0)
create a writer attached to an output stream.