Skip to content

Commit

Permalink
Sort attributes before writing reference
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelgk committed Oct 10, 2024
1 parent 2d61387 commit 4740106
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions include/c74_min_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,34 +284,42 @@ void doc_generate(const min_class_type& instance, const std::string& refpage_ful
refpage_file << " <attributelist>" << endl
<< endl;

// Write the attributes in alphabetical order
const auto& attributes = instance.attributes();

for (const auto& p : attributes) {
try {
const auto& attr_object = *p.second;
const auto& description = doc_format(attr_object.description_string());
const auto& attr_type = attr_object.datatype();

if (attr_object.visible() == visibility::hide) {
continue;
}

strncpy(digest, description.c_str(), digest_length_max);
char* c = strstr(digest, ". ");
if (!c) {
c = strchr(digest, '.');
}
if (c) {
*c = 0;
std::vector<std::string> attr_names;
for (const auto& [name, value]: attributes) {
attr_names.push_back(name);
}
std::sort(attr_names.begin(), attr_names.end());

for (const auto& name : attr_names) {
if (const auto& p = attributes.find(name); p != attributes.end()) {
try {
const auto& attr_object = *p.second;
const auto& description = doc_format(attr_object.description_string());
const auto& attr_type = attr_object.datatype();

if (attr_object.visible() == visibility::hide) {
continue;
}

strncpy(digest, description.c_str(), digest_length_max);
char* c = strstr(digest, ". ");
if (!c) {
c = strchr(digest, '.');
}
if (c) {
*c = 0;
}

refpage_file << " <attribute name='" << attr_object.name() << "' get='1' set='" << attr_object.writable() << "' type='" << attr_type << "' size='1' >" << endl;
refpage_file << " <digest>" << digest << "</digest>" << endl;
refpage_file << " <description>" << description << "</description>" << endl;
refpage_file << " </attribute>" << endl
<< endl;
} catch (...) {
// if an attr doesn't have a description or there is some other problem, just ignore this attribute
}

refpage_file << " <attribute name='" << attr_object.name() << "' get='1' set='" << attr_object.writable() << "' type='" << attr_type << "' size='1' >" << endl;
refpage_file << " <digest>" << digest << "</digest>" << endl;
refpage_file << " <description>" << description << "</description>" << endl;
refpage_file << " </attribute>" << endl
<< endl;
} catch (...) {
// if an attr doesn't have a description or there is some other problem, just ignore this attribute
}
}

Expand Down

0 comments on commit 4740106

Please sign in to comment.