Flow123d
JS_before_hm-1712-g4d968e368
|
Go to the documentation of this file.
28 #include <boost/algorithm/string/replace.hpp>
29 #include <boost/tokenizer.hpp>
30 #include <boost/functional/hash.hpp>
81 return rec->
data_->description_;
93 parent_vec = rec.
data_->parent_vec_;
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_impl(stream,
static_cast<const Type::Record *
>(type) );
144 print_impl(stream,
static_cast<const Type::Record *
>(type) );
147 print_impl(stream,
static_cast<const Type::Array *
>(type) );
159 print_impl(stream,
static_cast<const Type::Integer *
>(type) );
162 print_impl(stream,
static_cast<const Type::Double *
>(type) );
165 print_impl(stream,
static_cast<const Type::Bool *
>(type) );
171 if (file_name_type != NULL ) {
172 print_impl(stream, file_name_type );
177 if (string_type != NULL ) {
178 print_impl(stream, string_type );
183 THROW( Type::ExcUnknownDescendant() << Type::EI_TypeName(
typeid(type).name()) );
190 stream <<
"<" << dft.
value() <<
">";
192 stream <<
"\"" << dft.
value() <<
"\"";
197 unsigned int padding,
unsigned int hash_count) {
199 boost::replace_all(s,
"\\$",
"$");
201 boost::tokenizer<boost::char_separator<char> > line_tokenizer(s, boost::char_separator<char>(
"\n"));
202 boost::tokenizer<boost::char_separator<char> >::iterator
it;
205 for(
it = line_tokenizer.begin();
it != line_tokenizer.end(); ++
it) {
207 stream << setw(padding) <<
"";
208 stream << std::setfill(
'#') << setw(hash_count) <<
"" << std::setfill(
' ') <<
" " << *
it;
214 processed_types_hash_.clear();
221 bool in_set = ( processed_types_hash_.find(hash) != processed_types_hash_.end() );
222 if (! in_set) processed_types_hash_.insert(hash);
243 doc_type_ = full_record;
244 clear_processed_types();
246 print_base(stream, type_);
258 if (! was_written(hash)) {
271 if (key_it != type->
end()) {
272 stream <<
", reducible to key '" << key_it->key_ <<
"'";
274 stream <<
"" <<
" (" << type->
size() <<
" keys).";
277 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
279 doc_type_ = key_record;
281 size_setw_ =
it->key_.size() + 3;
282 stream << setw(padding_size) <<
"" <<
it->key_ <<
" = ";
283 write_default_value(stream,
it->default_);
285 stream << setw(padding_size + size_setw_) <<
"" <<
"#### is ";
286 print_base(stream,
it->type_.get());
287 write_description(stream,
it->description_, padding_size+size_setw_);
290 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
292 doc_type_ = full_record;
302 unsigned int lower_size, upper_size;
303 get_array_sizes(*type, lower_size, upper_size);
304 stream <<
"Array, size limits: [" << lower_size <<
", " << upper_size <<
"] of type: " << endl;
305 stream << setw(padding_size + size_setw_) <<
"" <<
"#### ";
319 stream <<
"Abstract '" << type->
type_name() <<
"' with "<< type->
child_size() <<
" descendants.";
323 if (! was_written(hash) ) {
326 stream <<
"" <<
"Abstract '" << type->
type_name() <<
"' with " << type->
child_size() <<
" descendants.";
329 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
331 doc_type_ = key_record;
334 stream << setw(padding_size) <<
"";
335 stream <<
"" <<
"Record '" << (*it).type_name() <<
"'";
339 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
341 doc_type_ = full_record;
350 if (doc_type_ == key_record) {
377 stream <<
"Selection '" << type->
type_name() <<
"' of " << type->
size() <<
" values.";
381 if (! was_written(hash) ) {
382 stream << endl <<
"Selection '" << type->
type_name() <<
"' of " << type->
size() <<
" values.";
385 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') << endl;
388 stream << setw(padding_size) <<
"" <<
it->key_ <<
" = " <<
it->value;
389 if (
it->description_ !=
"") {
391 stream << setw(padding_size +
it->key_.size() + 3) <<
"" <<
"# " <<
it->description_ <<
"";
395 stream <<
"" << std::setfill(
'-') << setw(10) <<
"" << std::setfill(
' ') <<
" " << type->
type_name() << endl;
401 if (doc_type_ == key_record) {
402 int lower_bound, upper_bound;
403 get_integer_bounds(*type, lower_bound, upper_bound);
404 stream <<
"Integer in [" << lower_bound <<
", " << upper_bound <<
"]";
408 if (doc_type_ == key_record) {
409 double lower_bound, upper_bound;
410 get_double_bounds(*type, lower_bound, upper_bound);
411 stream <<
"Double in [" << lower_bound <<
", " << upper_bound <<
"]";
415 if (doc_type_ == key_record) {
420 if (doc_type_ == key_record) {
425 if (doc_type_ == key_record) {
426 stream <<
"FileName of ";
428 case ::FilePath::input_file:
429 stream <<
"input file";
431 case ::FilePath::output_file:
432 stream <<
"output file";
435 stream <<
"file with unknown type";
444 ASSERT_DBG(
false).error(
"Parameter appears in the IST. Check where Instance is missing.");
478 {std::regex(
"\\\\"),
"\\\\"},
480 {std::regex(
"\\\""),
"\\\""},
482 {std::regex(
"\\n"),
"\\n"},
483 {std::regex(
"\\t"),
"\\t"},
484 {std::regex(
"\\r"),
"\\r"}
488 std::string tmp = std::string(desc);
490 for (
auto rewrite_rule : rewrite_rules) {
491 tmp = std::regex_replace(tmp, rewrite_rule.first, rewrite_rule.second);
530 if (attribute_map.size() == 0)
return "\"attributes\" : {}";
532 stream <<
"\"attributes\" : {" << endl;
533 for (
auto it=attribute_map.begin();
it!=attribute_map.end(); ++
it) {
534 if (
it != attribute_map.begin()) {
535 stream <<
"," << endl;
537 stream <<
"\"" <<
it->first <<
"\" : " <<
it->second;
539 stream << endl <<
"}";
546 stream <<
"{" << endl;
547 stream <<
"\"id\" : " << type->
hash_str() <<
"," << endl;
548 stream <<
"\"input_type\" : \"" + type->
class_name() +
"\"," << endl;
549 stream <<
"\"name\" : \"" << type->
type_name() <<
"\"," << endl;
558 stream <<
"\"generic_type\" : " <<
TypeBase::hash_str(generic_type_hash) <<
"," << endl;
560 if (parameter_map_to_json.size()) {
561 stream <<
"\"parameters\" : " << parameter_map_to_json <<
"," << endl;
569 print_generic<Tuple>(stream, type);
571 print_generic<Record>(stream, type);
578 stream <<
"," << endl <<
"\"description\" : \"" <<
584 if (parent_vec.size()) {
585 stream <<
"\"implements\" : [ ";
586 bool add_comma =
false;
587 for (
auto &parent : parent_vec) {
588 if (add_comma) stream <<
", ";
589 else add_comma =
true;
590 stream << parent->hash_str();
592 stream <<
" ]," << endl;
597 if (key_it != type->
end()) {
598 stream <<
"\"reducible_to_key\" : \"" << key_it->key_ <<
"\"," << endl;
601 stream <<
"\"keys\" : [" << endl;
605 string dft_type, dft_value;
607 if (dft_type !=
"value at declaration")
611 stream <<
"," << endl;
613 stream <<
"{ \"key\" : \"" <<
it->key_ <<
"\"," << endl;
614 stream <<
"\"description\" : \"" <<
616 stream <<
"\"default\" : { "
617 <<
"\"type\" : \"" << dft_type <<
"\"," << endl
618 <<
"\"value\" : " << dft_value <<
" }," << endl;
619 stream <<
"\"type\" : " <<
it->type_->hash_str() <<
"," << endl;
624 stream <<
"]" << endl;
642 unsigned int lower_size, upper_size;
649 stream <<
"," << endl;
650 stream <<
"\"range\" : [" << lower_size <<
", " << upper_size <<
"]," << endl;
651 stream <<
"\"subtype\" : " <<
array_type->hash_str() << endl;
652 stream <<
"}," << endl;
662 print_generic<Abstract>(stream, type);
668 stream <<
"," << endl;
669 stream <<
"\"description\" : \"" <<
684 print_generic<AdHocAbstract>(stream, type);
692 stream <<
"," << endl;
712 stream <<
"\"default_descendant\" : " << desc->
hash_str() <<
"," << endl;
714 stream <<
"\"implementations\" : [" << endl;
717 stream <<
"," << endl;
718 stream <<
"" <<
it->hash_str() <<
"";
729 print_generic<Selection>(stream, type);
735 stream <<
"," << endl;
736 stream <<
"\"description\" : \"" <<
739 stream <<
"\"values\" : [" << endl;
742 stream <<
"," << endl;
744 stream <<
"{ \"name\" : \"" <<
it->key_ <<
"\"," << endl;
750 stream <<
"]" << endl;
765 stream <<
"," << endl;
766 stream <<
"\"range\" : [" << lower <<
", " << upper <<
"]" << endl;
781 stream <<
"," << endl;
782 stream <<
"\"range\" : [" << lower <<
", " << upper <<
"]" << endl;
816 stream <<
"," << endl;
817 stream <<
"\"file_mode\" : \"";
819 case ::FilePath::input_file:
822 case ::FilePath::output_file:
823 stream <<
"output\"";
827 stream << endl <<
"},";
839 stream << endl <<
"},";
847 string build_date = string(__DATE__) +
", " + string(__TIME__);
849 stream <<
"{" << endl;
852 stream <<
"\"date\" : \"" << build_date <<
"\"" << endl;
868 return type_output.
print(stream) << endl;
873 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.
static constexpr bool value
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
ostream & print(ostream &stream) override
Performs output of the documentation into given stream.
void print_impl(ostream &stream, const Record *type)
Implements printout of Record type.
Class for create text documentation.