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_impl(stream, static_cast<const Type::Record *>(type) );
149 print_impl(stream, static_cast<const Type::Record *>(type) );
152 print_impl(stream, static_cast<const Type::Array *>(type) );
155 print_impl(stream, static_cast<const Type::Abstract *>(type) );
158 print_impl(stream, static_cast<const Type::AdHocAbstract *>(type) );
161 print_impl(stream, static_cast<const Type::Selection *>(type) );
164 print_impl(stream, static_cast<const Type::Integer *>(type) );
167 print_impl(stream, static_cast<const Type::Double *>(type) );
170 print_impl(stream, static_cast<const Type::Bool *>(type) );
173 print_impl(stream, static_cast<const Type::Parameter *>(type) );
176 if (file_name_type != NULL ) {
177 print_impl(stream, file_name_type );
182 if (string_type != NULL ) {
183 print_impl(stream, string_type );
188 THROW( Type::ExcUnknownDescendant() << Type::EI_TypeName(
typeid(type).name()) );
195 stream <<
"<" << dft.
value() <<
">";
197 stream <<
"\"" << dft.
value() <<
"\"";
202 unsigned int padding,
unsigned int hash_count) {
204 boost::replace_all(s,
"\\$",
"$");
206 boost::tokenizer<boost::char_separator<char> > line_tokenizer(s, boost::char_separator<char>(
"\n"));
207 boost::tokenizer<boost::char_separator<char> >::iterator
it;
210 for(it = line_tokenizer.begin(); it != line_tokenizer.end(); ++it) {
212 stream << setw(padding) <<
"";
213 stream << std::setfill(
'#') << setw(hash_count) <<
"" << std::setfill(
' ') <<
" " << *it;
219 processed_types_hash_.clear();
226 bool in_set = ( processed_types_hash_.find(hash) != processed_types_hash_.end() );
227 if (! in_set) processed_types_hash_.insert(hash);
248 doc_type_ = full_record;
249 clear_processed_types();
251 print_base(stream, type_);
263 if (! was_written(hash)) {
276 if (key_it != type->
end()) {
277 stream <<
", reducible to key '" << key_it->key_ <<
"'";
279 stream <<
"" <<
" (" << type->
size() <<
" keys).";
282 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
284 doc_type_ = key_record;
286 size_setw_ =
it->key_.size() + 3;
287 stream << setw(padding_size) <<
"" <<
it->key_ <<
" = ";
288 write_default_value(stream,
it->default_);
290 stream << setw(padding_size + size_setw_) <<
"" <<
"#### is ";
291 print_base(stream,
it->type_.get());
292 write_description(stream,
it->description_, padding_size+size_setw_);
295 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
297 doc_type_ = full_record;
304 get_array_type(*type, array_type);
307 unsigned int lower_size, upper_size;
308 get_array_sizes(*type, lower_size, upper_size);
309 stream <<
"Array, size limits: [" << lower_size <<
", " << upper_size <<
"] of type: " << endl;
310 stream << setw(padding_size + size_setw_) <<
"" <<
"#### ";
311 print_base(stream, array_type.get());
314 print_base(stream, array_type.get());
324 stream <<
"Abstract '" << type->
type_name() <<
"' with "<< type->
child_size() <<
" descendants.";
328 if (! was_written(hash) ) {
331 stream <<
"" <<
"Abstract '" << type->
type_name() <<
"' with " << type->
child_size() <<
" descendants.";
334 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
336 doc_type_ = key_record;
339 stream << setw(padding_size) <<
"";
340 stream <<
"" <<
"Record '" << (*it).type_name() <<
"'";
344 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
346 doc_type_ = full_record;
355 if (doc_type_ == key_record) {
382 stream <<
"Selection '" << type->
type_name() <<
"' of " << type->
size() <<
" values.";
386 if (! was_written(hash) ) {
387 stream << endl <<
"Selection '" << type->
type_name() <<
"' of " << type->
size() <<
" values.";
390 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
393 stream << setw(padding_size) <<
"" <<
it->key_ <<
" = " <<
it->value;
394 if (
it->description_ !=
"") {
396 stream << setw(padding_size +
it->key_.size() + 3) <<
"" <<
"# " <<
it->description_ <<
"";
400 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
406 if (doc_type_ == key_record) {
407 int lower_bound, upper_bound;
408 get_integer_bounds(*type, lower_bound, upper_bound);
409 stream <<
"Integer in [" << lower_bound <<
", " << upper_bound <<
"]";
413 if (doc_type_ == key_record) {
414 double lower_bound, upper_bound;
415 get_double_bounds(*type, lower_bound, upper_bound);
416 stream <<
"Double in [" << lower_bound <<
", " << upper_bound <<
"]";
420 if (doc_type_ == key_record) {
425 if (doc_type_ == key_record) {
430 if (doc_type_ == key_record) {
431 stream <<
"FileName of ";
433 case ::FilePath::input_file:
434 stream <<
"input file";
436 case ::FilePath::output_file:
437 stream <<
"output file";
440 stream <<
"file with unknown type";
449 ASSERT_DBG(
false).error(
"Parameter appears in the IST. Check where Instance is missing.");
483 {std::regex(
"\\\\"),
"\\\\"},
485 {std::regex(
"\\\""),
"\\\""},
487 {std::regex(
"\\n"),
"\\n"},
488 {std::regex(
"\\t"),
"\\t"},
489 {std::regex(
"\\r"),
"\\r"}
493 std::string tmp = std::string(desc);
495 for (
auto rewrite_rule : rewrite_rules) {
496 tmp = std::regex_replace(tmp, rewrite_rule.first, rewrite_rule.second);
535 if (attribute_map.size() == 0)
return "\"attributes\" : {}";
537 stream <<
"\"attributes\" : {" << endl;
538 for (
auto it=attribute_map.begin();
it!=attribute_map.end(); ++
it) {
539 if (
it != attribute_map.begin()) {
540 stream <<
"," << endl;
542 stream <<
"\"" <<
it->first <<
"\" : " <<
it->second;
544 stream << endl <<
"}";
551 stream <<
"{" << endl;
552 stream <<
"\"id\" : " << type->
hash_str() <<
"," << endl;
553 stream <<
"\"input_type\" : \"" + type->
class_name() +
"\"," << endl;
554 stream <<
"\"name\" : \"" << type->
type_name() <<
"\"," << endl;
563 stream <<
"\"generic_type\" : " <<
TypeBase::hash_str(generic_type_hash) <<
"," << endl;
565 if (parameter_map_to_json.size()) {
566 stream <<
"\"parameters\" : " << parameter_map_to_json <<
"," << endl;
574 print_generic<Tuple>(stream, type);
576 print_generic<Record>(stream, type);
583 stream <<
"," << endl <<
"\"description\" : \"" <<
589 if (parent_vec.size()) {
590 stream <<
"\"implements\" : [ ";
591 bool add_comma =
false;
592 for (
auto &parent : parent_vec) {
593 if (add_comma) stream <<
", ";
594 else add_comma =
true;
595 stream << parent->hash_str();
597 stream <<
" ]," << endl;
602 if (key_it != type->
end()) {
603 stream <<
"\"reducible_to_key\" : \"" << key_it->key_ <<
"\"," << endl;
606 stream <<
"\"keys\" : [" << endl;
610 string dft_type, dft_value;
612 if (dft_type !=
"value at declaration")
616 stream <<
"," << endl;
618 stream <<
"{ \"key\" : \"" <<
it->key_ <<
"\"," << endl;
619 stream <<
"\"description\" : \"" <<
621 stream <<
"\"default\" : { " 622 <<
"\"type\" : \"" << dft_type <<
"\"," << endl
623 <<
"\"value\" : " << dft_value <<
" }," << endl;
624 stream <<
"\"type\" : " <<
it->type_->hash_str() <<
"," << endl;
629 stream <<
"]" << endl;
647 unsigned int lower_size, upper_size;
654 stream <<
"," << endl;
655 stream <<
"\"range\" : [" << lower_size <<
", " << upper_size <<
"]," << endl;
656 stream <<
"\"subtype\" : " << array_type->hash_str() << endl;
657 stream <<
"}," << endl;
667 print_generic<Abstract>(stream, type);
673 stream <<
"," << endl;
674 stream <<
"\"description\" : \"" <<
689 print_generic<AdHocAbstract>(stream, type);
697 stream <<
"," << endl;
717 stream <<
"\"default_descendant\" : " << desc->
hash_str() <<
"," << endl;
719 stream <<
"\"implementations\" : [" << endl;
722 stream <<
"," << endl;
723 stream <<
"" <<
it->hash_str() <<
"";
734 print_generic<Selection>(stream, type);
740 stream <<
"," << endl;
741 stream <<
"\"description\" : \"" <<
744 stream <<
"\"values\" : [" << endl;
747 stream <<
"," << endl;
749 stream <<
"{ \"name\" : \"" <<
it->key_ <<
"\"," << endl;
755 stream <<
"]" << endl;
770 stream <<
"," << endl;
771 stream <<
"\"range\" : [" << lower <<
", " << upper <<
"]" << endl;
786 stream <<
"," << endl;
787 stream <<
"\"range\" : [" << lower <<
", " << upper <<
"]" << endl;
821 stream <<
"," << endl;
822 stream <<
"\"file_mode\" : \"";
824 case ::FilePath::input_file:
827 case ::FilePath::output_file:
828 stream <<
"output\"";
832 stream << endl <<
"},";
844 stream << endl <<
"},";
852 string build_date = string(__DATE__) +
", " + string(__TIME__);
854 stream <<
"{" << endl;
857 stream <<
"\"date\" : \"" << build_date <<
"\"" << endl;
873 return type_output.
print(stream) << endl;
878 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.