23 #include <boost/algorithm/string/replace.hpp> 24 #include <boost/iostreams/filtering_stream.hpp> 25 #include <boost/iostreams/concepts.hpp> 26 #include <boost/iostreams/operations.hpp> 31 #include <boost/regex.hpp> 69 lower = array.
data_->lower_bound_;
70 upper = array.
data_->upper_bound_;
76 arr_type = array.
data_->type_of_values_;
82 return rec->
data_->description_;
94 parent_vec = rec.
data_->parent_vec_;
100 value = it->default_.value_;
101 if ( it->default_.is_obligatory() ) {
103 }
else if ( it->default_.is_optional() ) {
105 }
else if ( it->default_.has_value_at_read_time() ) {
106 type =
"value at read time";
108 type =
"value at declaration";
115 return sel->
data_->description_;
134 print_impl(stream, static_cast<const Type::Record *>(type) );
137 print_impl(stream, static_cast<const Type::Array *>(type) );
140 print_impl(stream, static_cast<const Type::Abstract *>(type) );
143 print_impl(stream, static_cast<const Type::AdHocAbstract *>(type) );
146 print_impl(stream, static_cast<const Type::Selection *>(type) );
149 print_impl(stream, static_cast<const Type::Integer *>(type) );
152 print_impl(stream, static_cast<const Type::Double *>(type) );
155 print_impl(stream, static_cast<const Type::Bool *>(type) );
158 print_impl(stream, static_cast<const Type::Parameter *>(type) );
161 if (file_name_type != NULL ) {
162 print_impl(stream, file_name_type );
167 if (string_type != NULL ) {
168 print_impl(stream, string_type );
173 THROW( Type::ExcUnknownDescendant() << Type::EI_TypeName(
typeid(type).name()) );
180 stream <<
"<" << dft.
value() <<
">";
182 stream <<
"\"" << dft.
value() <<
"\"";
187 unsigned int padding,
unsigned int hash_count) {
189 boost::replace_all(s,
"\\$",
"$");
191 boost::tokenizer<boost::char_separator<char> > line_tokenizer(s, boost::char_separator<char>(
"\n"));
192 boost::tokenizer<boost::char_separator<char> >::iterator
it;
195 for(it = line_tokenizer.begin(); it != line_tokenizer.end(); ++it) {
197 stream << setw(padding) <<
"";
198 stream << std::setfill(
'#') << setw(hash_count) <<
"" << std::setfill(
' ') <<
" " << *it;
204 processed_types_hash_.clear();
211 bool in_set = ( processed_types_hash_.find(hash) != processed_types_hash_.end() );
212 if (! in_set) processed_types_hash_.insert(hash);
233 doc_type_ = full_record;
234 clear_processed_types();
236 print_base(stream, type_);
248 if (! was_written(hash)) {
261 if (key_it != type->
end()) {
262 stream <<
", reducible to key '" << key_it->key_ <<
"'";
264 stream <<
"" <<
" (" << type->
size() <<
" keys).";
267 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
269 doc_type_ = key_record;
271 size_setw_ =
it->key_.size() + 3;
272 stream << setw(padding_size) <<
"" <<
it->key_ <<
" = ";
273 write_default_value(stream,
it->default_);
275 stream << setw(padding_size + size_setw_) <<
"" <<
"#### is ";
276 print_base(stream,
it->type_.get());
277 write_description(stream,
it->description_, padding_size+size_setw_);
280 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
282 doc_type_ = full_record;
289 get_array_type(*type, array_type);
292 unsigned int lower_size, upper_size;
293 get_array_sizes(*type, lower_size, upper_size);
294 stream <<
"Array, size limits: [" << lower_size <<
", " << upper_size <<
"] of type: " << endl;
295 stream << setw(padding_size + size_setw_) <<
"" <<
"#### ";
296 print_base(stream, array_type.get());
299 print_base(stream, array_type.get());
309 stream <<
"Abstract '" << type->
type_name() <<
"' with "<< type->
child_size() <<
" descendants.";
313 if (! was_written(hash) ) {
316 stream <<
"" <<
"Abstract '" << type->
type_name() <<
"' with " << type->
child_size() <<
" descendants.";
319 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
321 doc_type_ = key_record;
324 stream << setw(padding_size) <<
"";
325 stream <<
"" <<
"Record '" << (*it).type_name() <<
"'";
329 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
331 doc_type_ = full_record;
340 if (doc_type_ == key_record) {
341 stream <<
"AdHocAbstract";
367 stream <<
"Selection '" << type->
type_name() <<
"' of " << type->
size() <<
" values.";
371 if (! was_written(hash) ) {
372 stream << endl <<
"Selection '" << type->
type_name() <<
"' of " << type->
size() <<
" values.";
375 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
378 stream << setw(padding_size) <<
"" <<
it->key_ <<
" = " <<
it->value;
379 if (
it->description_ !=
"") {
381 stream << setw(padding_size +
it->key_.size() + 3) <<
"" <<
"# " <<
it->description_ <<
"";
385 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
391 if (doc_type_ == key_record) {
392 int lower_bound, upper_bound;
393 get_integer_bounds(*type, lower_bound, upper_bound);
394 stream <<
"Integer in [" << lower_bound <<
", " << upper_bound <<
"]";
398 if (doc_type_ == key_record) {
399 double lower_bound, upper_bound;
400 get_double_bounds(*type, lower_bound, upper_bound);
401 stream <<
"Double in [" << lower_bound <<
", " << upper_bound <<
"]";
405 if (doc_type_ == key_record) {
410 if (doc_type_ == key_record) {
411 stream <<
"String (generic)";
415 if (doc_type_ == key_record) {
416 stream <<
"FileName of ";
418 case ::FilePath::input_file:
419 stream <<
"input file";
421 case ::FilePath::output_file:
422 stream <<
"output file";
425 stream <<
"file with unknown type";
434 ASSERT_DBG(
false).error(
"Parameter appears in the IST. Check where Instance is missing.");
467 {boost::regex(
"\\\\"),
"\\\\\\\\"},
469 {boost::regex(
"\\\""),
"\\\\\""},
471 {boost::regex(
"\\n"),
"\\\\n"},
472 {boost::regex(
"\\t"),
"\\\\t"},
473 {boost::regex(
"\\r"),
"\\\\r"}
477 std::string tmp = std::string(desc);
479 for (
auto rewrite_rule : rewrite_rules) {
480 tmp = boost::regex_replace(tmp, rewrite_rule.first, rewrite_rule.second);
518 if (attribute_map.size() == 0)
return "\"attributes\" : {}";
520 stream <<
"\"attributes\" : {" << endl;
521 for (
auto it=attribute_map.begin();
it!=attribute_map.end(); ++
it) {
522 if (
it != attribute_map.begin()) {
523 stream <<
"," << endl;
525 stream <<
"\"" <<
it->first <<
"\" : " <<
it->second;
527 stream << endl <<
"}";
534 stream <<
"{" << endl;
535 stream <<
"\"id\" : " << type->
hash_str() <<
"," << endl;
536 stream <<
"\"input_type\" : \"" + type->
class_name() +
"\"," << endl;
537 stream <<
"\"name\" : \"" << type->
type_name() <<
"\"," << endl;
545 if (generic_type_hash) {
546 stream <<
"\"generic_type\" : " <<
TypeBase::hash_str(generic_type_hash) <<
"," << endl;
548 if (parameter_map_to_json.size()) {
549 stream <<
"\"parameters\" : " << parameter_map_to_json <<
"," << endl;
561 stream <<
"," << endl <<
"\"description\" : \"" <<
567 if (parent_vec.size()) {
568 stream <<
"\"implements\" : [ ";
569 bool add_comma =
false;
570 for (
auto &parent : parent_vec) {
571 if (add_comma) stream <<
", ";
572 else add_comma =
true;
573 stream << parent->hash_str();
575 stream <<
" ]," << endl;
580 if (key_it != type->
end()) {
581 stream <<
"\"reducible_to_key\" : \"" << key_it->key_ <<
"\"," << endl;
584 stream <<
"\"keys\" : [" << endl;
588 string dft_type, dft_value;
590 if (dft_type !=
"value at declaration")
594 stream <<
"," << endl;
596 stream <<
"{ \"key\" : \"" <<
it->key_ <<
"\"," << endl;
597 stream <<
"\"description\" : \"" <<
599 stream <<
"\"default\" : { " 600 <<
"\"type\" : \"" << dft_type <<
"\"," << endl
601 <<
"\"value\" : " << dft_value <<
" }," << endl;
602 stream <<
"\"type\" : " <<
it->type_->hash_str() <<
"," << endl;
607 stream <<
"]" << endl;
625 unsigned int lower_size, upper_size;
632 stream <<
"," << endl;
633 stream <<
"\"range\" : [" << lower_size <<
", " << upper_size <<
"]," << endl;
634 stream <<
"\"subtype\" : " << array_type->hash_str() << endl;
635 stream <<
"}," << endl;
649 stream <<
"," << endl;
650 stream <<
"\"description\" : \"" <<
671 stream <<
"," << endl;
691 stream <<
"\"default_descendant\" : " << desc->
hash_str() <<
"," << endl;
693 stream <<
"\"implementations\" : [" << endl;
696 stream <<
"," << endl;
697 stream <<
"" <<
it->hash_str() <<
"";
712 stream <<
"," << endl;
713 stream <<
"\"description\" : \"" <<
716 stream <<
"\"values\" : [" << endl;
719 stream <<
"," << endl;
721 stream <<
"{ \"name\" : \"" <<
it->key_ <<
"\"," << endl
725 stream <<
"]" << endl;
740 stream <<
"," << endl;
741 stream <<
"\"range\" : [" << lower <<
", " << upper <<
"]" << endl;
756 stream <<
"," << endl;
757 stream <<
"\"range\" : [" << lower <<
", " << upper <<
"]" << endl;
791 stream <<
"," << endl;
792 stream <<
"\"file_mode\" : \"";
794 case ::FilePath::input_file:
797 case ::FilePath::output_file:
798 stream <<
"output\"";
802 stream << endl <<
"},";
814 stream << endl <<
"},";
822 string build_date = string(__DATE__) +
", " + string(__TIME__);
824 stream <<
"{" << endl;
827 stream <<
"\"date\" : \"" << build_date <<
"\"" << endl;
843 return type_output.
print(stream) << endl;
848 return type_output.
print(stream) << endl;
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
void print_impl(ostream &stream, const Record *type)
Implements printout of Record type.
ostream & print(ostream &stream) override
Performs output of the documentation into given stream.
Class for create text documentation.
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.