29 #include <boost/algorithm/string/replace.hpp> 30 #include <boost/tokenizer.hpp> 35 #include <boost/functional/hash.hpp> 73 lower = array.
data_->lower_bound_;
74 upper = array.
data_->upper_bound_;
80 arr_type = array.
data_->type_of_values_;
86 return rec->
data_->description_;
98 parent_vec = rec.
data_->parent_vec_;
104 value = it->default_.value_;
105 if ( it->default_.is_obligatory() ) {
107 }
else if ( it->default_.is_optional() ) {
109 }
else if ( it->default_.has_value_at_read_time() ) {
110 type =
"value at read time";
112 type =
"value at declaration";
119 return sel->
data_->description_;
138 print_base(stream, gen_type);
146 print_generic<Tuple>(stream, type);
147 print_impl(stream, static_cast<const Type::Record *>(type) );
150 print_generic<Record>(stream, type);
151 print_impl(stream, static_cast<const Type::Record *>(type) );
154 print_impl(stream, static_cast<const Type::Array *>(type) );
157 print_impl(stream, static_cast<const Type::Abstract *>(type) );
160 print_impl(stream, static_cast<const Type::AdHocAbstract *>(type) );
163 print_impl(stream, static_cast<const Type::Selection *>(type) );
166 print_impl(stream, static_cast<const Type::Integer *>(type) );
169 print_impl(stream, static_cast<const Type::Double *>(type) );
172 print_impl(stream, static_cast<const Type::Bool *>(type) );
175 print_impl(stream, static_cast<const Type::Parameter *>(type) );
178 if (file_name_type != NULL ) {
179 print_impl(stream, file_name_type );
184 if (string_type != NULL ) {
185 print_impl(stream, string_type );
190 THROW( Type::ExcUnknownDescendant() << Type::EI_TypeName(
typeid(type).name()) );
197 stream <<
"<" << dft.
value() <<
">";
199 stream <<
"\"" << dft.
value() <<
"\"";
204 unsigned int padding,
unsigned int hash_count) {
206 boost::replace_all(s,
"\\$",
"$");
208 boost::tokenizer<boost::char_separator<char> > line_tokenizer(s, boost::char_separator<char>(
"\n"));
209 boost::tokenizer<boost::char_separator<char> >::iterator
it;
212 for(it = line_tokenizer.begin(); it != line_tokenizer.end(); ++it) {
214 stream << setw(padding) <<
"";
215 stream << std::setfill(
'#') << setw(hash_count) <<
"" << std::setfill(
' ') <<
" " << *it;
221 processed_types_hash_.clear();
228 bool in_set = ( processed_types_hash_.find(hash) != processed_types_hash_.end() );
229 if (! in_set) processed_types_hash_.insert(hash);
250 doc_type_ = full_record;
251 clear_processed_types();
253 print_base(stream, type_);
265 if (! was_written(hash)) {
278 if (key_it != type->
end()) {
279 stream <<
", reducible to key '" << key_it->key_ <<
"'";
281 stream <<
"" <<
" (" << type->
size() <<
" keys).";
284 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
286 doc_type_ = key_record;
288 size_setw_ =
it->key_.size() + 3;
289 stream << setw(padding_size) <<
"" <<
it->key_ <<
" = ";
290 write_default_value(stream,
it->default_);
292 stream << setw(padding_size + size_setw_) <<
"" <<
"#### is ";
293 print_base(stream,
it->type_.get());
294 write_description(stream,
it->description_, padding_size+size_setw_);
297 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
299 doc_type_ = full_record;
306 get_array_type(*type, array_type);
309 unsigned int lower_size, upper_size;
310 get_array_sizes(*type, lower_size, upper_size);
311 stream <<
"Array, size limits: [" << lower_size <<
", " << upper_size <<
"] of type: " << endl;
312 stream << setw(padding_size + size_setw_) <<
"" <<
"#### ";
313 print_base(stream, array_type.get());
316 print_base(stream, array_type.get());
326 stream <<
"Abstract '" << type->
type_name() <<
"' with "<< type->
child_size() <<
" descendants.";
330 if (! was_written(hash) ) {
333 stream <<
"" <<
"Abstract '" << type->
type_name() <<
"' with " << type->
child_size() <<
" descendants.";
336 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
338 doc_type_ = key_record;
341 stream << setw(padding_size) <<
"";
342 stream <<
"" <<
"Record '" << (*it).type_name() <<
"'";
346 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
348 doc_type_ = full_record;
357 if (doc_type_ == key_record) {
358 stream <<
"AdHocAbstract";
384 stream <<
"Selection '" << type->
type_name() <<
"' of " << type->
size() <<
" values.";
388 if (! was_written(hash) ) {
389 stream << endl <<
"Selection '" << type->
type_name() <<
"' of " << type->
size() <<
" values.";
392 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
395 stream << setw(padding_size) <<
"" <<
it->key_ <<
" = " <<
it->value;
396 if (
it->description_ !=
"") {
398 stream << setw(padding_size +
it->key_.size() + 3) <<
"" <<
"# " <<
it->description_ <<
"";
402 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
408 if (doc_type_ == key_record) {
409 int lower_bound, upper_bound;
410 get_integer_bounds(*type, lower_bound, upper_bound);
411 stream <<
"Integer in [" << lower_bound <<
", " << upper_bound <<
"]";
415 if (doc_type_ == key_record) {
416 double lower_bound, upper_bound;
417 get_double_bounds(*type, lower_bound, upper_bound);
418 stream <<
"Double in [" << lower_bound <<
", " << upper_bound <<
"]";
422 if (doc_type_ == key_record) {
427 if (doc_type_ == key_record) {
428 stream <<
"String (generic)";
432 if (doc_type_ == key_record) {
433 stream <<
"FileName of ";
435 case ::FilePath::input_file:
436 stream <<
"input file";
438 case ::FilePath::output_file:
439 stream <<
"output file";
442 stream <<
"file with unknown type";
451 ASSERT_DBG(
false).error(
"Parameter appears in the IST. Check where Instance is missing.");
485 {std::regex(
"\\\\"),
"\\\\"},
487 {std::regex(
"\\\""),
"\\\""},
489 {std::regex(
"\\n"),
"\\n"},
490 {std::regex(
"\\t"),
"\\t"},
491 {std::regex(
"\\r"),
"\\r"}
495 std::string tmp = std::string(desc);
497 for (
auto rewrite_rule : rewrite_rules) {
498 tmp = std::regex_replace(tmp, rewrite_rule.first, rewrite_rule.second);
537 if (attribute_map.size() == 0)
return "\"attributes\" : {}";
539 stream <<
"\"attributes\" : {" << endl;
540 for (
auto it=attribute_map.begin();
it!=attribute_map.end(); ++
it) {
541 if (
it != attribute_map.begin()) {
542 stream <<
"," << endl;
544 stream <<
"\"" <<
it->first <<
"\" : " <<
it->second;
546 stream << endl <<
"}";
553 stream <<
"{" << endl;
554 stream <<
"\"id\" : " << type->
hash_str() <<
"," << endl;
555 stream <<
"\"input_type\" : \"" + type->
class_name() +
"\"," << endl;
556 stream <<
"\"name\" : \"" << type->
type_name() <<
"\"," << endl;
564 if (generic_type_hash) {
565 stream <<
"\"generic_type\" : " <<
TypeBase::hash_str(generic_type_hash) <<
"," << endl;
567 if (parameter_map_to_json.size()) {
568 stream <<
"\"parameters\" : " << parameter_map_to_json <<
"," << endl;
580 stream <<
"," << endl <<
"\"description\" : \"" <<
586 if (parent_vec.size()) {
587 stream <<
"\"implements\" : [ ";
588 bool add_comma =
false;
589 for (
auto &parent : parent_vec) {
590 if (add_comma) stream <<
", ";
591 else add_comma =
true;
592 stream << parent->hash_str();
594 stream <<
" ]," << endl;
599 if (key_it != type->
end()) {
600 stream <<
"\"reducible_to_key\" : \"" << key_it->key_ <<
"\"," << endl;
603 stream <<
"\"keys\" : [" << endl;
607 string dft_type, dft_value;
609 if (dft_type !=
"value at declaration")
613 stream <<
"," << endl;
615 stream <<
"{ \"key\" : \"" <<
it->key_ <<
"\"," << endl;
616 stream <<
"\"description\" : \"" <<
618 stream <<
"\"default\" : { " 619 <<
"\"type\" : \"" << dft_type <<
"\"," << endl
620 <<
"\"value\" : " << dft_value <<
" }," << endl;
621 stream <<
"\"type\" : " <<
it->type_->hash_str() <<
"," << endl;
626 stream <<
"]" << endl;
644 unsigned int lower_size, upper_size;
651 stream <<
"," << endl;
652 stream <<
"\"range\" : [" << lower_size <<
", " << upper_size <<
"]," << endl;
653 stream <<
"\"subtype\" : " << array_type->hash_str() << endl;
654 stream <<
"}," << endl;
664 print_generic<Abstract>(stream, type);
670 stream <<
"," << endl;
671 stream <<
"\"description\" : \"" <<
686 print_generic<AdHocAbstract>(stream, type);
694 stream <<
"," << endl;
714 stream <<
"\"default_descendant\" : " << desc->
hash_str() <<
"," << endl;
716 stream <<
"\"implementations\" : [" << endl;
719 stream <<
"," << endl;
720 stream <<
"" <<
it->hash_str() <<
"";
731 print_generic<Selection>(stream, type);
737 stream <<
"," << endl;
738 stream <<
"\"description\" : \"" <<
741 stream <<
"\"values\" : [" << endl;
744 stream <<
"," << endl;
746 stream <<
"{ \"name\" : \"" <<
it->key_ <<
"\"," << endl;
752 stream <<
"]" << endl;
767 stream <<
"," << endl;
768 stream <<
"\"range\" : [" << lower <<
", " << upper <<
"]" << endl;
783 stream <<
"," << endl;
784 stream <<
"\"range\" : [" << lower <<
", " << upper <<
"]" << endl;
818 stream <<
"," << endl;
819 stream <<
"\"file_mode\" : \"";
821 case ::FilePath::input_file:
824 case ::FilePath::output_file:
825 stream <<
"output\"";
829 stream << endl <<
"},";
841 stream << endl <<
"},";
849 string build_date = string(__DATE__) +
", " + string(__TIME__);
851 stream <<
"{" << endl;
854 stream <<
"\"date\" : \"" << build_date <<
"\"" << endl;
870 return type_output.
print(stream) << endl;
875 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.