24 #include <boost/algorithm/string/replace.hpp> 25 #include <boost/iostreams/filtering_stream.hpp> 26 #include <boost/iostreams/concepts.hpp> 27 #include <boost/iostreams/operations.hpp> 32 #include <boost/regex.hpp> 68 lower = array.
data_->lower_bound_;
69 upper = array.
data_->upper_bound_;
75 arr_type = array.
data_->type_of_values_;
81 return rec->
data_->description_;
93 parent_vec = rec.
data_->parent_vec_;
99 value = it->default_.value_;
100 if ( it->default_.is_obligatory() ) {
102 }
else if ( it->default_.is_optional() ) {
104 }
else if ( it->default_.has_value_at_read_time() ) {
105 type =
"value at read time";
107 type =
"value at declaration";
114 return sel->
data_->description_;
133 print_base(stream, gen_type);
141 print_generic<Tuple>(stream, type);
142 print_impl(stream, static_cast<const Type::Record *>(type) );
145 print_generic<Record>(stream, type);
146 print_impl(stream, static_cast<const Type::Record *>(type) );
149 print_impl(stream, static_cast<const Type::Array *>(type) );
152 print_impl(stream, static_cast<const Type::Abstract *>(type) );
155 print_impl(stream, static_cast<const Type::AdHocAbstract *>(type) );
158 print_impl(stream, static_cast<const Type::Selection *>(type) );
161 print_impl(stream, static_cast<const Type::Integer *>(type) );
164 print_impl(stream, static_cast<const Type::Double *>(type) );
167 print_impl(stream, static_cast<const Type::Bool *>(type) );
170 print_impl(stream, static_cast<const Type::Parameter *>(type) );
173 if (file_name_type != NULL ) {
174 print_impl(stream, file_name_type );
179 if (string_type != NULL ) {
180 print_impl(stream, string_type );
185 THROW( Type::ExcUnknownDescendant() << Type::EI_TypeName(
typeid(type).name()) );
192 stream <<
"<" << dft.
value() <<
">";
194 stream <<
"\"" << dft.
value() <<
"\"";
199 unsigned int padding,
unsigned int hash_count) {
201 boost::replace_all(s,
"\\$",
"$");
203 boost::tokenizer<boost::char_separator<char> > line_tokenizer(s, boost::char_separator<char>(
"\n"));
204 boost::tokenizer<boost::char_separator<char> >::iterator
it;
207 for(it = line_tokenizer.begin(); it != line_tokenizer.end(); ++it) {
209 stream << setw(padding) <<
"";
210 stream << std::setfill(
'#') << setw(hash_count) <<
"" << std::setfill(
' ') <<
" " << *it;
216 processed_types_hash_.clear();
223 bool in_set = ( processed_types_hash_.find(hash) != processed_types_hash_.end() );
224 if (! in_set) processed_types_hash_.insert(hash);
245 doc_type_ = full_record;
246 clear_processed_types();
248 print_base(stream, type_);
260 if (! was_written(hash)) {
273 if (key_it != type->
end()) {
274 stream <<
", reducible to key '" << key_it->key_ <<
"'";
276 stream <<
"" <<
" (" << type->
size() <<
" keys).";
279 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
281 doc_type_ = key_record;
283 size_setw_ =
it->key_.size() + 3;
284 stream << setw(padding_size) <<
"" <<
it->key_ <<
" = ";
285 write_default_value(stream,
it->default_);
287 stream << setw(padding_size + size_setw_) <<
"" <<
"#### is ";
288 print_base(stream,
it->type_.get());
289 write_description(stream,
it->description_, padding_size+size_setw_);
292 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
294 doc_type_ = full_record;
301 get_array_type(*type, array_type);
304 unsigned int lower_size, upper_size;
305 get_array_sizes(*type, lower_size, upper_size);
306 stream <<
"Array, size limits: [" << lower_size <<
", " << upper_size <<
"] of type: " << endl;
307 stream << setw(padding_size + size_setw_) <<
"" <<
"#### ";
308 print_base(stream, array_type.get());
311 print_base(stream, array_type.get());
321 stream <<
"Abstract '" << type->
type_name() <<
"' with "<< type->
child_size() <<
" descendants.";
325 if (! was_written(hash) ) {
328 stream <<
"" <<
"Abstract '" << type->
type_name() <<
"' with " << type->
child_size() <<
" descendants.";
331 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
333 doc_type_ = key_record;
336 stream << setw(padding_size) <<
"";
337 stream <<
"" <<
"Record '" << (*it).type_name() <<
"'";
341 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
343 doc_type_ = full_record;
352 if (doc_type_ == key_record) {
353 stream <<
"AdHocAbstract";
379 stream <<
"Selection '" << type->
type_name() <<
"' of " << type->
size() <<
" values.";
383 if (! was_written(hash) ) {
384 stream << endl <<
"Selection '" << type->
type_name() <<
"' of " << type->
size() <<
" values.";
387 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
390 stream << setw(padding_size) <<
"" <<
it->key_ <<
" = " <<
it->value;
391 if (
it->description_ !=
"") {
393 stream << setw(padding_size +
it->key_.size() + 3) <<
"" <<
"# " <<
it->description_ <<
"";
397 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
403 if (doc_type_ == key_record) {
404 int lower_bound, upper_bound;
405 get_integer_bounds(*type, lower_bound, upper_bound);
406 stream <<
"Integer in [" << lower_bound <<
", " << upper_bound <<
"]";
410 if (doc_type_ == key_record) {
411 double lower_bound, upper_bound;
412 get_double_bounds(*type, lower_bound, upper_bound);
413 stream <<
"Double in [" << lower_bound <<
", " << upper_bound <<
"]";
417 if (doc_type_ == key_record) {
422 if (doc_type_ == key_record) {
423 stream <<
"String (generic)";
427 if (doc_type_ == key_record) {
428 stream <<
"FileName of ";
430 case ::FilePath::input_file:
431 stream <<
"input file";
433 case ::FilePath::output_file:
434 stream <<
"output file";
437 stream <<
"file with unknown type";
446 ASSERT_DBG(
false).error(
"Parameter appears in the IST. Check where Instance is missing.");
480 {boost::regex(
"\\\\"),
"\\\\\\\\"},
482 {boost::regex(
"\\\""),
"\\\\\""},
484 {boost::regex(
"\\n"),
"\\\\n"},
485 {boost::regex(
"\\t"),
"\\\\t"},
486 {boost::regex(
"\\r"),
"\\\\r"}
490 std::string tmp = std::string(desc);
492 for (
auto rewrite_rule : rewrite_rules) {
493 tmp = boost::regex_replace(tmp, rewrite_rule.first, rewrite_rule.second);
532 if (attribute_map.size() == 0)
return "\"attributes\" : {}";
534 stream <<
"\"attributes\" : {" << endl;
535 for (
auto it=attribute_map.begin();
it!=attribute_map.end(); ++
it) {
536 if (
it != attribute_map.begin()) {
537 stream <<
"," << endl;
539 stream <<
"\"" <<
it->first <<
"\" : " <<
it->second;
541 stream << endl <<
"}";
548 stream <<
"{" << endl;
549 stream <<
"\"id\" : " << type->
hash_str() <<
"," << endl;
550 stream <<
"\"input_type\" : \"" + type->
class_name() +
"\"," << endl;
551 stream <<
"\"name\" : \"" << type->
type_name() <<
"\"," << endl;
559 if (generic_type_hash) {
560 stream <<
"\"generic_type\" : " <<
TypeBase::hash_str(generic_type_hash) <<
"," << endl;
562 if (parameter_map_to_json.size()) {
563 stream <<
"\"parameters\" : " << parameter_map_to_json <<
"," << endl;
575 stream <<
"," << endl <<
"\"description\" : \"" <<
581 if (parent_vec.size()) {
582 stream <<
"\"implements\" : [ ";
583 bool add_comma =
false;
584 for (
auto &parent : parent_vec) {
585 if (add_comma) stream <<
", ";
586 else add_comma =
true;
587 stream << parent->hash_str();
589 stream <<
" ]," << endl;
594 if (key_it != type->
end()) {
595 stream <<
"\"reducible_to_key\" : \"" << key_it->key_ <<
"\"," << endl;
598 stream <<
"\"keys\" : [" << endl;
602 string dft_type, dft_value;
604 if (dft_type !=
"value at declaration")
608 stream <<
"," << endl;
610 stream <<
"{ \"key\" : \"" <<
it->key_ <<
"\"," << endl;
611 stream <<
"\"description\" : \"" <<
613 stream <<
"\"default\" : { " 614 <<
"\"type\" : \"" << dft_type <<
"\"," << endl
615 <<
"\"value\" : " << dft_value <<
" }," << endl;
616 stream <<
"\"type\" : " <<
it->type_->hash_str() <<
"," << endl;
621 stream <<
"]" << endl;
639 unsigned int lower_size, upper_size;
646 stream <<
"," << endl;
647 stream <<
"\"range\" : [" << lower_size <<
", " << upper_size <<
"]," << endl;
648 stream <<
"\"subtype\" : " << array_type->hash_str() << endl;
649 stream <<
"}," << endl;
659 print_generic<Abstract>(stream, type);
665 stream <<
"," << endl;
666 stream <<
"\"description\" : \"" <<
681 print_generic<AdHocAbstract>(stream, type);
689 stream <<
"," << endl;
709 stream <<
"\"default_descendant\" : " << desc->
hash_str() <<
"," << endl;
711 stream <<
"\"implementations\" : [" << endl;
714 stream <<
"," << endl;
715 stream <<
"" <<
it->hash_str() <<
"";
726 print_generic<Selection>(stream, type);
732 stream <<
"," << endl;
733 stream <<
"\"description\" : \"" <<
736 stream <<
"\"values\" : [" << endl;
739 stream <<
"," << endl;
741 stream <<
"{ \"name\" : \"" <<
it->key_ <<
"\"," << endl;
747 stream <<
"]" << endl;
762 stream <<
"," << endl;
763 stream <<
"\"range\" : [" << lower <<
", " << upper <<
"]" << endl;
778 stream <<
"," << endl;
779 stream <<
"\"range\" : [" << lower <<
", " << upper <<
"]" << endl;
813 stream <<
"," << endl;
814 stream <<
"\"file_mode\" : \"";
816 case ::FilePath::input_file:
819 case ::FilePath::output_file:
820 stream <<
"output\"";
824 stream << endl <<
"},";
836 stream << endl <<
"},";
844 string build_date = string(__DATE__) +
", " + string(__TIME__);
846 stream <<
"{" << endl;
849 stream <<
"\"date\" : \"" << build_date <<
"\"" << endl;
865 return type_output.
print(stream) << endl;
870 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.
static constexpr bool value
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.