generilaze the output of an eoState : now you can change the format, comes with defaults formatting (latex and json)
This commit is contained in:
parent
854c65f582
commit
f7b9db1358
2 changed files with 125 additions and 12 deletions
|
|
@ -18,7 +18,7 @@ using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void removeComment(string& str, string comment)
|
void eoState::removeComment(string& str, string comment)
|
||||||
{
|
{
|
||||||
string::size_type pos = str.find(comment);
|
string::size_type pos = str.find(comment);
|
||||||
|
|
||||||
|
|
@ -28,21 +28,23 @@ void removeComment(string& str, string comment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_section(const string& str, string& name)
|
bool eoState::is_section(const string& str, string& name)
|
||||||
{
|
{
|
||||||
string::size_type pos = str.find("\\section{");
|
string::size_type pos = str.find(_tag_section_so);
|
||||||
|
|
||||||
if (pos == string::npos)
|
if (pos == string::npos)
|
||||||
return false;
|
return false;
|
||||||
//else
|
//else
|
||||||
|
|
||||||
string::size_type end = str.find("}");
|
string::size_type end = str.find(_tag_section_sc);
|
||||||
|
|
||||||
if (end == string::npos)
|
if (end == string::npos)
|
||||||
return false;
|
return false;
|
||||||
// else
|
// else
|
||||||
|
|
||||||
name = str.substr(pos + 9, end-9);
|
// affect name, passed by reference
|
||||||
|
// Note: substr( start, count )
|
||||||
|
name = str.substr( pos + _tag_section_so.size(), end - _tag_section_so.size() );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -84,6 +86,7 @@ void eoState::load(const string& _filename)
|
||||||
load(is);
|
load(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME implement parsing and loading of other formats
|
||||||
void eoState::load(std::istream& is)
|
void eoState::load(std::istream& is)
|
||||||
{
|
{
|
||||||
string str;
|
string str;
|
||||||
|
|
@ -158,16 +161,49 @@ void eoState::save(const string& filename) const
|
||||||
save(os);
|
save(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
void eoState::save(std::ostream& os) const
|
//void eoState::save(std::ostream& os) const
|
||||||
{ // saves in order of insertion
|
//{ // saves in order of insertion
|
||||||
for (vector<ObjectMap::iterator>::const_iterator it = creationOrder.begin(); it != creationOrder.end(); ++it)
|
// for (vector<ObjectMap::iterator>::const_iterator it = creationOrder.begin(); it != creationOrder.end(); ++it)
|
||||||
{
|
// {
|
||||||
os << "\\section{" << (*it)->first << "}\n";
|
// os << "\\section{" << (*it)->first << "}\n";
|
||||||
(*it)->second->printOn(os);
|
// (*it)->second->printOn(os);
|
||||||
os << '\n';
|
// os << '\n';
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
void eoState::saveSection( std::ostream& os, vector<ObjectMap::iterator>::const_iterator it) const
|
||||||
|
{
|
||||||
|
os << _tag_section_so << (*it)->first << _tag_section_sc;
|
||||||
|
|
||||||
|
os << _tag_content_s;
|
||||||
|
(*it)->second->printOn(os);
|
||||||
|
os << _tag_content_e;
|
||||||
|
|
||||||
|
os << _tag_section_e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void eoState::save(std::ostream& os) const
|
||||||
|
{
|
||||||
|
os << _tag_state_so << _tag_state_name << _tag_state_sc;
|
||||||
|
|
||||||
|
// save the first section
|
||||||
|
assert( creationOrder.size() > 0 );
|
||||||
|
// saves in order of insertion
|
||||||
|
vector<ObjectMap::iterator>::const_iterator it = creationOrder.begin();
|
||||||
|
saveSection(os,it);
|
||||||
|
it++;
|
||||||
|
|
||||||
|
while( it != creationOrder.end() ) {
|
||||||
|
// add a separator only before [1,n] elements
|
||||||
|
os << _tag_section_sep;
|
||||||
|
saveSection(os, it);
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
os << _tag_state_e;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
string eoState::createObjectName(eoObject* obj)
|
string eoState::createObjectName(eoObject* obj)
|
||||||
{
|
{
|
||||||
if (obj == 0)
|
if (obj == 0)
|
||||||
|
|
|
||||||
|
|
@ -56,10 +56,50 @@ class eoState : public eoFunctorStore
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
eoState(void) {}
|
eoState(std::string name="") :
|
||||||
|
_tag_state_so(""),
|
||||||
|
_tag_state_name(name),
|
||||||
|
_tag_state_sc(""),
|
||||||
|
_tag_section_so("\\section{"),
|
||||||
|
_tag_section_sc("}\n"),
|
||||||
|
_tag_content_s(""),
|
||||||
|
_tag_content_e(""),
|
||||||
|
_tag_section_sep(""),
|
||||||
|
_tag_section_e("\n"),
|
||||||
|
_tag_state_e("")
|
||||||
|
{}
|
||||||
|
|
||||||
~eoState(void);
|
~eoState(void);
|
||||||
|
|
||||||
|
void formatLatex(std::string name)
|
||||||
|
{
|
||||||
|
_tag_state_so = "";
|
||||||
|
_tag_state_name = name;
|
||||||
|
_tag_state_sc = "";
|
||||||
|
_tag_section_so = "\\section{";
|
||||||
|
_tag_section_sc = "}\n";
|
||||||
|
_tag_content_s = "";
|
||||||
|
_tag_content_e = "";
|
||||||
|
_tag_section_sep = "";
|
||||||
|
_tag_section_e = "\n";
|
||||||
|
_tag_state_e = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void formatJSON(std::string name)
|
||||||
|
{
|
||||||
|
_tag_state_so = "{ \"";
|
||||||
|
_tag_state_name = name;
|
||||||
|
_tag_state_sc = "\":\n";
|
||||||
|
_tag_section_so = "\t{ \"";
|
||||||
|
_tag_section_sc = "\":\n";
|
||||||
|
_tag_content_s = "\"";
|
||||||
|
_tag_content_e = "\"";
|
||||||
|
_tag_section_sep = ",\n";
|
||||||
|
_tag_section_e = "\t}\n";
|
||||||
|
_tag_state_e = "}\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object registration function, note that it does not take ownership!
|
* Object registration function, note that it does not take ownership!
|
||||||
*/
|
*/
|
||||||
|
|
@ -131,6 +171,43 @@ private :
|
||||||
eoState(const eoState&);
|
eoState(const eoState&);
|
||||||
eoState& operator=(const eoState&);
|
eoState& operator=(const eoState&);
|
||||||
|
|
||||||
|
/* \@{
|
||||||
|
* s=start, e=end
|
||||||
|
* o=open, c=close
|
||||||
|
*
|
||||||
|
* { "my_state":
|
||||||
|
* {
|
||||||
|
* "section_pop":"…",
|
||||||
|
* "section_rng":"…"
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* // JSON LATEX (default)
|
||||||
|
*/
|
||||||
|
std::string _tag_state_so; // { "
|
||||||
|
std::string _tag_state_name; // my_state
|
||||||
|
std::string _tag_state_sc; // ":
|
||||||
|
|
||||||
|
std::string _tag_section_so; // { " \\section{
|
||||||
|
std::string _tag_section_sc; // ": }\n
|
||||||
|
|
||||||
|
std::string _tag_content_s; // "
|
||||||
|
std::string _tag_content_e; // "
|
||||||
|
|
||||||
|
std::string _tag_section_sep;// ,
|
||||||
|
|
||||||
|
std::string _tag_section_e; // } \n
|
||||||
|
|
||||||
|
std::string _tag_state_e; // }
|
||||||
|
/** \@} */
|
||||||
|
|
||||||
|
void removeComment( std::string& str, std::string comment);
|
||||||
|
|
||||||
|
bool is_section(const std::string& str, std::string& name);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void saveSection( std::ostream& os, std::vector<ObjectMap::iterator>::const_iterator it) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
/** @example t-eoStateAndParser.cpp
|
/** @example t-eoStateAndParser.cpp
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Reference in a new issue