26 #include "ObjCryst/RefinableObj/RefinableObj.h"
27 #include "ObjCryst/RefinableObj/IO.h"
36 XMLCrystTag::XMLCrystTag():
37 mIsEndTag(false),mIsEmptyTag(false)
40 XMLCrystTag::XMLCrystTag(istream &is)
45 XMLCrystTag::XMLCrystTag(
const string &tagName,
47 const bool isEmptyTag):
48 mName(tagName),mIsEndTag(isEndTag),mIsEmptyTag(isEmptyTag)
51 XMLCrystTag::~XMLCrystTag(){}
53 const string& XMLCrystTag::GetName()
const{
return mName;}
54 const string& XMLCrystTag::GetClassName()
const{
static string str=
"XMLCrystTag";
return str;}
56 unsigned int XMLCrystTag::GetNbAttribute()
const{
return mvAttribute.size();}
58 void XMLCrystTag::AddAttribute(
const string &attName,
const string &attValue)
60 VFN_DEBUG_ENTRY(
"XMLCrystTag::AddAttribute():"<<this->GetName(),4)
61 mvAttribute.push_back(make_pair(attName,attValue));
62 VFN_DEBUG_EXIT("XMLCrystTag::AddAttribute():"<<this->GetName(),4)
64 void XMLCrystTag::GetAttribute(const
int attNum,
string &attName,
string &attValue)
66 attName=mvAttribute[attNum].first;
67 attValue=mvAttribute[attNum].second;
70 const string& XMLCrystTag::GetAttributeName(
const int attNum)
const
71 {
return mvAttribute[attNum].first;}
73 const string& XMLCrystTag::GetAttributeValue(
const int attNum)
const
74 {
return mvAttribute[attNum].second;}
76 void XMLCrystTag::SetIsEndTag(
const bool isEndTag){mIsEndTag=isEndTag;}
77 bool XMLCrystTag::IsEndTag()
const{
return mIsEndTag;}
78 void XMLCrystTag::SetIsEmptyTag(
const bool isEmptyTag){mIsEmptyTag=isEmptyTag;}
79 bool XMLCrystTag::IsEmptyTag()
const{
return mIsEmptyTag;}
80 void XMLCrystTag::Print()
const{cout<<*
this;}
82 WXCrystObj* XMLCrystTag::WXCreate(wxWindow *parent)
86 return mpWXXMLCrystTag;
88 WXCrystObj* XMLCrystTag::WXGet()
90 return mpWXXMLCrystTag;
92 void XMLCrystTag::WXDelete()
94 if(0!=mpWXXMLCrystTag)
delete mpWXXMLCrystTag;
97 void XMLCrystTag::WXNotifyDelete()
105 if(
true==tag.mIsEndTag)
107 os <<
"</"<<tag.mName<<
">";
111 for(
unsigned int i=0;i<tag.GetNbAttribute();i++)
113 os<<
" "<<tag.mvAttribute[i].first<<
"=\""<<tag.mvAttribute[i].second<<
"\"";
115 if(
true==tag.mIsEmptyTag) os <<
"/>";
121 ios::fmtflags f=is.flags();
122 is.unsetf(ios::skipws);
123 tag.mIsEmptyTag=
false;
127 while ((tmp!=
'<') && !(is.eof()) && !(is.fail()) )is>>tmp;
128 if(is.eof())
return is;
129 if(is.fail()) {cout<<
"throw:"<<__FILE__<<
":"<<__LINE__<<
":"<<tag<<endl;
throw ObjCrystException(
"XMLCrystTag::>> failed input");}
130 while ((tmp==
' ')||(tmp==
'<'))is>>tmp;
135 while ((tmp==
' ')||(tmp==
'/'))is>>tmp;
143 VFN_DEBUG_MESSAGE(str,1);
144 if(is.fail()) {cout<<
"throw:"<<__FILE__<<
":"<<__LINE__<<
":"<<tag<<endl;
throw ObjCrystException(
"XMLCrystTag::>> failed input");}
145 }
while ((tmp!=
' ')&&(tmp!=
'>')&&(tmp!=
'/'));
151 while(tmp==
' ')is>>tmp;
161 tag.mIsEmptyTag=
true;
166 do {str+=tmp;is>>tmp;VFN_DEBUG_MESSAGE(str,1)}
while ((tmp!=
' ')&&(tmp!=
'='));
167 while(tmp!=
'"')is>>tmp;
170 if(tmp!=
'"')
do {str2+=tmp;is>>tmp;VFN_DEBUG_MESSAGE(str2,1)}
while (tmp!=
'"');
173 tag.AddAttribute(str,str2);
186 VFN_DEBUG_ENTRY(
"RefinablePar::XMLOutput():"<<this->GetName(),5)
190 ss <<!(this->IsFixed());
191 tag.AddAttribute(
"Refined",ss.str());
195 ss <<this->IsLimited();
196 tag.AddAttribute(
"Limited",ss.str());
200 ss <<this->GetHumanMin();
201 tag.AddAttribute(
"Min",ss.str());
205 ss <<this->GetHumanMax();
206 tag.AddAttribute(
"Max",ss.str());
211 ss <<this->IsPeriodic();
212 tag.AddAttribute(
"Periodic",ss.str());
216 tag.AddAttribute(
"Name",name);
218 for(
int i=0;i<indent;i++) os <<
" " ;
220 tag.SetIsEndTag(
true);
221 os <<this->GetHumanValue()<<tag;
222 VFN_DEBUG_EXIT(
"RefinablePar::XMLOutput():"<<this->GetName(),5)
226 this->XMLOutput(os,mName,indent);
231 VFN_DEBUG_ENTRY(
"RefinablePar::XMLInput():"<<this->GetName(),5)
232 for(
unsigned int i=0;i<tag.GetNbAttribute();i++)
234 if(
"Name"==tag.GetAttributeName(i))
continue;
235 if(
"Refined"==tag.GetAttributeName(i))
238 stringstream ss(tag.GetAttributeValue(i));
239 ss.imbue(std::locale::classic());
241 this->SetIsFixed(!b);
244 if(
"Limited"==tag.GetAttributeName(i))
247 stringstream ss(tag.GetAttributeValue(i));
248 ss.imbue(std::locale::classic());
250 this->SetIsLimited(b);
253 if(
"Min"==tag.GetAttributeName(i))
256 stringstream ss(tag.GetAttributeValue(i));
257 ss.imbue(std::locale::classic());
259 this->SetHumanMin(f);
262 if(
"Max"==tag.GetAttributeName(i))
265 stringstream ss(tag.GetAttributeValue(i));
266 ss.imbue(std::locale::classic());
268 this->SetHumanMax(f);
271 if(
"Periodic"==tag.GetAttributeName(i))
274 stringstream ss(tag.GetAttributeValue(i));
275 ss.imbue(std::locale::classic());
277 this->SetIsPeriodic(b);
281 VFN_DEBUG_MESSAGE(tag, 10)
284 this->SetHumanValue(f);
286 VFN_DEBUG_MESSAGE(tag, 10)
287 VFN_DEBUG_EXIT(
"RefinablePar::XMLInput():"<<this->GetName(),5)
297 VFN_DEBUG_ENTRY(
"RefObjOpt::XMLOutput():"<<this->GetName(),5)
299 tag.AddAttribute(
"Name",this->GetName());
302 ss <<this->GetChoice();
303 tag.AddAttribute(
"Choice",ss.str());
305 tag.AddAttribute(
"ChoiceName",this->GetChoiceName(this->GetChoice()));
307 for(
int i=0;i<indent;i++) os <<
" " ;
310 VFN_DEBUG_EXIT(
"RefObjOpt::XMLOutput():"<<this->GetName(),5)
315 VFN_DEBUG_ENTRY(
"RefObjOpt::XMLInput():"<<this->GetName(),5)
316 for(
unsigned int i=0;i<tag.GetNbAttribute();i++)
318 if(
"Name"==tag.GetAttributeName(i))
continue;
319 if(
"ChoiceName"==tag.GetAttributeName(i))
continue;
320 if(
"Choice"==tag.GetAttributeName(i))
323 stringstream ss(tag.GetAttributeValue(i));
329 VFN_DEBUG_EXIT(
"RefObjOpt::XMLInput():"<<this->GetName(),5)
338 VFN_DEBUG_MESSAGE(
"RefinableObj::XMLOutput():"<<this->GetName(),5)
343 VFN_DEBUG_MESSAGE(
"RefinableObj::XMLInput():"<<this->GetName(),5)
346 void RefinableObj::XMLInputOld(istream &is,
const IOCrystTag &tag)
348 VFN_DEBUG_MESSAGE(
"RefinableObj::XMLInput():"<<this->GetName(),5)
357 void IOCrystExtractNameSpace(istream &is,
string &str)
359 ios::fmtflags f=is.flags();
360 is.unsetf(ios::skipws);
362 do {is>>tmp;}
while (tmp==
' ');
364 do {str+=tmp;is>>tmp;VFN_DEBUG_MESSAGE(str,1)}
while ((tmp!=
' ')&&(tmp!=
'>'));
365 if(tmp==
'>') is.putback(tmp);
369 void IOCrystExtractNameLine(istream &is,
string &str)
371 ios::fmtflags f=is.flags();
372 is.setf(ios::skipws);
377 void IOCrystExtractNameQuoted(istream &is,
string &str)
380 do {is>>tmp;}
while ((tmp!=
'\'')&&(tmp!=
'\"'));
383 if((tmp==
'\'')||(tmp==
'\"'))
return;
384 ios::fmtflags f=is.flags();
385 is.unsetf(ios::skipws);
386 do {str+=tmp;is>>tmp;VFN_DEBUG_MESSAGE(str,1)}
while ((tmp!=
'\'')&&(tmp!=
'\"'));
390 void IOCrystXMLOutputNameQuoted(ostream &os,
const string &str)
392 os <<
'\"' << str <<
'\"';
401 IOCrystTag::IOCrystTag(
const string& type,
const string& name,
const unsigned long version):
402 mTagType(type),mTagName(name),mTagVersion(version),mIsClosingTag(false)
404 IOCrystTag::IOCrystTag(istream &is)
406 VFN_DEBUG_MESSAGE(
"IOCrystTag::IOCrystTag(istream &is)",2)
420 IOCrystExtractNameSpace(is,mTagType);
421 VFN_DEBUG_MESSAGE(
"IOCrystTag::IOCrystTag(istream &is):TagType:"<<mTagType,1)
422 if(*(mTagType.c_str())=='\\')
430 IOCrystExtractNameQuoted(is,mTagName);
434 do {is>>tmp;}
while (tmp!=
'>');
435 VFN_DEBUG_MESSAGE(
"IOCrystTag::IOCrystTag(istream &is):End",2)
437 IOCrystTag::~IOCrystTag(){}
439 bool IOCrystTag::operator==(
const IOCrystTag& rhs)
const
441 if( (rhs.GetType()==this->GetType()) && (rhs.GetName()==this->GetName()))
return true;
444 void IOCrystTag::XMLInput(istream &is)
446 VFN_DEBUG_MESSAGE(
"IOCrystTag::XMLInput(istream &is)",2)
448 do {is>>tmp;}
while ((tmp!=
'<') && (!is.eof()) );
450 IOCrystExtractNameSpace(is,mTagType);
451 VFN_DEBUG_MESSAGE(
"IOCrystTag::XMLInput(istream &is):TagType:"<<mTagType,1)
452 if(*(mTagType.c_str())=='\\')
460 IOCrystExtractNameQuoted(is,mTagName);
464 do {is>>tmp;}
while (tmp!=
'>');
465 VFN_DEBUG_MESSAGE(
"IOCrystTag::XMLInput(istream &is):End",2)
467 const string &IOCrystTag::GetType()
const{
return mTagType;}
468 const string &IOCrystTag::GetName()
const{
return mTagName;}
469 unsigned long IOCrystTag::GetVersion()
const{
return mTagVersion;}
470 bool IOCrystTag::IsClosingTag()
const{
return mIsClosingTag;}
471 void IOCrystTag::Print()
const
473 if(mIsClosingTag==
true) cout <<
"<"<<mTagType<<
">"<<endl;
475 cout <<
"<"<<mTagType<<
" \""<<mTagName<<
"\" "<<mTagVersion<<
">"<<endl;
477 const string &IOCrystTag::GetClassName()
const{
return mTagType;}
479 WXCrystObj* IOCrystTag::WXCreate(wxWindow *parent)
482 return mpWXIOCrystTag;
484 WXCrystObj* IOCrystTag::WXGet()
486 return mpWXIOCrystTag;
488 void IOCrystTag::WXDelete()
490 if(0!=mpWXIOCrystTag)
delete mpWXIOCrystTag;
493 void IOCrystTag::WXNotifyDelete()
bool ISNAN_OR_INF(REAL r)
Test if the value is a NaN.
friend istream & operator>>(istream &, XMLCrystTag &)
Input an XMLCrystTag from a stream.
void XMLInput(istream &is, const XMLCrystTag &tag)
XMLInput From stream.
void XMLInput(istream &is, const XMLCrystTag &tag)
XMLInput From stream.
float InputFloat(istream &is, const char endchar)
Safely read a floating-point value from a stream.
void XMLOutput(ostream &os, int indent=0) const
XMLOutput to stream in well-formed XML.
virtual void XMLOutput(ostream &os, int indent=0) const
Output to stream in well-formed XML.
friend ostream & operator<<(ostream &, const XMLCrystTag &)
Output an XMLCrystTag to a stream.
Exception class for ObjCryst++ library.
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
class to input or output a well-formatted xml beginning or ending tag.
void XMLOutput(ostream &os, const string &name, int indent=0) const
XMLOutput to stream in well-formed XML.
virtual void XMLInput(istream &is, const XMLCrystTag &tag)
Input From stream.