diff --git a/src/BroDoc.cc b/src/BroDoc.cc index 2aa949e440..d0815abe4a 100644 --- a/src/BroDoc.cc +++ b/src/BroDoc.cc @@ -112,8 +112,11 @@ void BroDoc::WriteDocFile() const WriteSectionHeading("Summary", '-'); WriteStringList("%s\n", "%s\n\n", summary); - WriteToDoc(":Imports: "); - WriteStringList(":doc:`%s`, ", ":doc:`%s`\n", imports); + if ( ! imports.empty() ) + { + WriteToDoc(":Imports: "); + WriteStringList(":doc:`%s`, ", ":doc:`%s`\n", imports); + } WriteToDoc("\n"); @@ -182,16 +185,23 @@ void BroDoc::WriteBroDocObjList(const std::list& l, const char* heading, char underline) const { - WriteSectionHeading(heading, underline); + if ( l.empty() ) return; + std::list::const_iterator it; - for ( it = l.begin(); it != l.end(); ++it ) + bool (*f_ptr)(const BroDocObj* o) = 0; + + if ( wantPublic ) + f_ptr = IsPublicAPI; + else + f_ptr = IsPrivateAPI; + + it = std::find_if(l.begin(), l.end(), f_ptr); + if ( it == l.end() ) return; + WriteSectionHeading(heading, underline); + while ( it != l.end() ) { - if ( wantPublic ) - if ( (*it)->IsPublicAPI() ) - (*it)->WriteReST(reST_file); - else - if ( ! (*it)->IsPublicAPI() ) - (*it)->WriteReST(reST_file); + (*it)->WriteReST(reST_file); + it = find_if(++it, l.end(), f_ptr); } } diff --git a/src/BroDoc.h b/src/BroDoc.h index 7cee9faf1a..04d8206eaa 100644 --- a/src/BroDoc.h +++ b/src/BroDoc.h @@ -242,6 +242,9 @@ private: * @param a reference to a list of BroDocObj pointers */ void FreeBroDocObjPtrList(std::list& l); + + static bool IsPublicAPI(const BroDocObj* o) { return o->IsPublicAPI(); } + static bool IsPrivateAPI(const BroDocObj* o) { return ! o->IsPublicAPI(); } }; #endif diff --git a/src/BroDocObj.cc b/src/BroDocObj.cc index 326550e545..c04dba9a89 100644 --- a/src/BroDocObj.cc +++ b/src/BroDocObj.cc @@ -44,3 +44,9 @@ void BroDocObj::WriteReST(FILE* file) const fprintf(file, "\n"); } + +bool BroDocObj::IsPublicAPI() const + { + return (broID->Scope() == SCOPE_GLOBAL) || + (broID->Scope() == SCOPE_MODULE && broID->IsExport()); + } diff --git a/src/BroDocObj.h b/src/BroDocObj.h index 601d5f148b..fc33372043 100644 --- a/src/BroDocObj.h +++ b/src/BroDocObj.h @@ -41,9 +41,9 @@ public: * other words, this means that the identifier is declared as part of * the global scope (has GLOBAL namespace or is exported from another * namespace). - * @return true if the ID was declared in an export section, else false + * @return true if the identifier is part of the script's public API */ - bool IsPublicAPI() const { return broID->IsGlobal(); } + bool IsPublicAPI() const; /** * Return whether this object has documentation (## comments)