Improved autodoc documentation for standard ruby methods
and for STL containers, using %feature instead of hard-coding the stuff in ruby.cxx. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9753 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
75f1af27a5
commit
d3945a4d40
7 changed files with 125 additions and 51 deletions
|
|
@ -58,6 +58,11 @@
|
|||
* ------------------------------------------------------------ */
|
||||
%include <rubykw.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Documentation for common Ruby methods
|
||||
* ------------------------------------------------------------ */
|
||||
%include <rubyautodoc.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* The Ruby initialization function
|
||||
* ------------------------------------------------------------ */
|
||||
|
|
|
|||
54
Lib/ruby/rubyautodoc.swg
Normal file
54
Lib/ruby/rubyautodoc.swg
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* @file rubyautodoc.swg
|
||||
* @author gga
|
||||
* @date Wed May 2 16:41:59 2007
|
||||
*
|
||||
* @brief This file implements autodoc typemaps for some common
|
||||
* ruby methods.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
%define AUTODOC(func, str)
|
||||
%feature("autodoc", str) func;
|
||||
%enddef
|
||||
|
||||
|
||||
AUTODOC(to_a, "Convert class to an Array");
|
||||
AUTODOC(to_s, "Convert class to a String representation");
|
||||
AUTODOC(inspect, "Inspect class and its contents");
|
||||
AUTODOC(__getitem__, "Element accessor/slicing");
|
||||
AUTODOC(__setitem__, "Element setter/slicing");
|
||||
AUTODOC(operator==, "Equality comparison operator");
|
||||
AUTODOC(operator<=, "Lower or equal comparison operator");
|
||||
AUTODOC(operator>=, "Higher or equal comparison operator");
|
||||
AUTODOC(operator<, "Lower than comparison operator");
|
||||
AUTODOC(operator>, "Higher than comparison operator");
|
||||
AUTODOC(operator<<, "Left shifting or appending operator");
|
||||
AUTODOC(operator>>, "Right shifting operator or extracting operator");
|
||||
AUTODOC(operator+, "Add operator");
|
||||
AUTODOC(operator-, "Substraction operator");
|
||||
AUTODOC(operator+(), "Positive operator");
|
||||
AUTODOC(operator-(), "Negation operator");
|
||||
AUTODOC(operator&, "AND operator");
|
||||
AUTODOC(operator|, "OR operator");
|
||||
AUTODOC(operator^, "XOR operator");
|
||||
AUTODOC(operator~, "Invert operator");
|
||||
AUTODOC(__pow__, "Exponential operator");
|
||||
AUTODOC(__divmod__, "Modulo of division");
|
||||
AUTODOC(hash, "Hashing function for class");
|
||||
AUTODOC(dup, "Create a duplicate of the class and unfreeze it if needed");
|
||||
AUTODOC(clone, "Create a duplicate of the class");
|
||||
AUTODOC(coerce, "Coerce class to a number");
|
||||
AUTODOC(__cmp__, "Comparison operator");
|
||||
AUTODOC(size, "Size or Length of the container");
|
||||
AUTODOC(slice, "Return a slice (portion of) the container");
|
||||
AUTODOC(each, "Iterate thru each element in the container. A block must be provided");
|
||||
AUTODOC(find, "Find an element in the class or container");
|
||||
AUTODOC(each_key, "Iterate thru each key element in the container. A block must be provided");
|
||||
AUTODOC(each_value, "Iterate thru each key element in the container. A block must be provided");
|
||||
AUTODOC(reject, "Iterate thru each element in the container and reject those that fail a condition returning a new container. A block must be provided");
|
||||
AUTODOC(reject_bang, "Iterate thru each element in the container and reject those that fail a condition. A block must be provided. Container is modified in place");
|
||||
AUTODOC(select, "Iterate thru each element in the container and select those that match a condition. A block must be provided");
|
||||
|
||||
|
||||
28
Lib/ruby/rubystdautodoc.swg
Normal file
28
Lib/ruby/rubystdautodoc.swg
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* @file rubystdautodoc.swg
|
||||
* @author gga
|
||||
* @date Wed May 2 17:20:39 2007
|
||||
*
|
||||
* @brief This file contains autodocs for standard STL functions.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
//
|
||||
// For STL autodocumentation
|
||||
//
|
||||
AUTODOC(c_str, "Convert class to a String representation");
|
||||
AUTODOC(begin, "Return an iterator to the beginning of the container");
|
||||
AUTODOC(end, "Return an iterator to past the end of the container");
|
||||
AUTODOC(rbegin, "Return a reverse iterator to the beginning (the end) of the container");
|
||||
AUTODOC(rend, "Return a reverse iterator to past the end (past the beginning) of the container");
|
||||
AUTODOC(length, "Size or Length of the container");
|
||||
AUTODOC(resize, "Resize the size of the container");
|
||||
AUTODOC(capacity, "Reserved capacity of the container");
|
||||
AUTODOC(reserve, "Reserve memory in the container for a number of elements");
|
||||
AUTODOC(erase, "Delete a portion of the container");
|
||||
AUTODOC(max_size, "Maximum size of elements allowed in the container");
|
||||
AUTODOC(iterator, "Return an iterator to the container");
|
||||
AUTODOC(empty, "Check if the container is empty or not");
|
||||
AUTODOC(rfind, "Find an element in reverse usually starting from the end of the container");
|
||||
AUTODOC(substr, "Return a portion of the String");
|
||||
|
|
@ -203,3 +203,4 @@ namespace swig {
|
|||
|
||||
#define SWIG_RUBY_THREAD_BEGIN_BLOCK
|
||||
#define SWIG_RUBY_THREAD_END_BLOCK
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
%include <std/std_except.i>
|
||||
%include <rubystdcommon.swg>
|
||||
%include <rubystdautodoc.swg>
|
||||
|
||||
//
|
||||
// Use the following macro with modern STL implementations
|
||||
//
|
||||
|
|
|
|||
|
|
@ -2,5 +2,9 @@
|
|||
%warnfilter(801) std::string; // wrong class name
|
||||
%warnfilter(378) std::basic_string::operator!=;
|
||||
|
||||
|
||||
%rename("empty?") std::string::empty;
|
||||
%rename("empty?") std::basic_string::empty;
|
||||
|
||||
%include <typemaps/std_string.swg>
|
||||
|
||||
|
|
|
|||
|
|
@ -145,33 +145,6 @@ struct Autodoc {
|
|||
|
||||
|
||||
static const Autodoc kAutoDocs[] = {
|
||||
{ "to_a", "Convert class to an Array" },
|
||||
{ "to_s", "Convert class to a String representation" },
|
||||
{ "inspect", "Inspect class and its contents" },
|
||||
{ "[]", "Element accessor/slicing" },
|
||||
{ "[]=", "Element setter/slicing" },
|
||||
{ "==", "Equality comparison operator" },
|
||||
{ "<=", "Lower or equal comparison operator" },
|
||||
{ ">=", "Higher or equal comparison operator" },
|
||||
{ "<", "Lower than comparison operator" },
|
||||
{ ">", "Higher than comparison operator" },
|
||||
{ "<<", "Left shifting or appending operator" },
|
||||
{ ">>", "Right shifting operator or extracting operator" },
|
||||
{ "+", "Add operator" },
|
||||
{ "-", "Substraction operator" },
|
||||
{ "+@", "Positive operator" },
|
||||
{ "-@", "Negation operator" },
|
||||
{ "&", "AND operator" },
|
||||
{ "|", "OR operator" },
|
||||
{ "^", "XOR operator" },
|
||||
{ "~", "Invert operator" },
|
||||
{ "**", "Exponential operator" },
|
||||
{ "divmod", "Modulo of division" },
|
||||
{ "hash", "Hashing function for class" },
|
||||
{ "dup", "Create a duplicate of the class and unfreeze it if needed" },
|
||||
{ "clone", "Create a duplicate of the class" },
|
||||
{ "coerce", "Coerce class to a number" },
|
||||
{ "<=>", "Comparison operator" },
|
||||
{0,0}
|
||||
};
|
||||
|
||||
|
|
@ -335,7 +308,7 @@ private:
|
|||
const int maxwidth = 50;
|
||||
|
||||
if (pdocs)
|
||||
Append(pdocs, "\n");
|
||||
Append(pdocs, ".\n");
|
||||
|
||||
|
||||
Swig_typemap_attach_parms("in", plist, 0);
|
||||
|
|
@ -393,7 +366,7 @@ private:
|
|||
if (pdoc) {
|
||||
if (!pdocs)
|
||||
pdocs = NewString("Parameters:\n");
|
||||
Printf(pdocs, " %s\n", pdoc);
|
||||
Printf(pdocs, " %s.\n", pdoc);
|
||||
}
|
||||
} else {
|
||||
Append(doc, "?");
|
||||
|
|
@ -529,8 +502,26 @@ private:
|
|||
|
||||
|
||||
if (skipAuto) {
|
||||
Append(doc, autodoc);
|
||||
}
|
||||
if ( counter == 0 ) Printf(doc, " call-seq:\n");
|
||||
switch( ad_type )
|
||||
{
|
||||
case AUTODOC_STATICFUNC:
|
||||
case AUTODOC_FUNC:
|
||||
case AUTODOC_METHOD:
|
||||
{
|
||||
String *paramList = make_autodocParmList(n, showTypes);
|
||||
if (Len(paramList))
|
||||
Printf(doc, " %s(%s)", symname, paramList);
|
||||
else
|
||||
Printf(doc, " %s", symname);
|
||||
if (type)
|
||||
Printf(doc, " -> %s", type);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (ad_type) {
|
||||
case AUTODOC_CLASS:
|
||||
|
|
@ -585,8 +576,8 @@ private:
|
|||
Append(doc, "\n");
|
||||
}
|
||||
|
||||
Printf(doc, "\n\n");
|
||||
if (!skipAuto) {
|
||||
Printf(doc, "\n\n ");
|
||||
switch (ad_type) {
|
||||
case AUTODOC_CLASS:
|
||||
break;
|
||||
|
|
@ -606,24 +597,7 @@ private:
|
|||
break;
|
||||
|
||||
case AUTODOC_METHOD:
|
||||
bool found = false;
|
||||
if ( symname )
|
||||
{
|
||||
const Autodoc* d = kAutoDocs;
|
||||
for ( ; d->symname != NULL; ++d )
|
||||
{
|
||||
if ( Cmp(symname, d->symname) == 0 )
|
||||
{
|
||||
found = true;
|
||||
Printf(doc, "%s.\n", d->description);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
Printf(doc, "A method.\n");
|
||||
}
|
||||
Printf(doc, "A method.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -642,20 +616,26 @@ private:
|
|||
case NO_AUTODOC:
|
||||
case NAMES_AUTODOC:
|
||||
case TYPES_AUTODOC:
|
||||
case STRING_AUTODOC:
|
||||
extended = 0;
|
||||
break;
|
||||
case STRING_AUTODOC:
|
||||
extended = 2;
|
||||
Printv(doc, autodoc, ".", NIL);
|
||||
break;
|
||||
case EXTEND_AUTODOC:
|
||||
case EXTEND_TYPES_AUTODOC:
|
||||
extended = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (extended) {
|
||||
String *pdocs = Getattr(n, "feature:pdocs");
|
||||
if (pdocs) {
|
||||
Printv(doc, "\n\n", pdocs, NULL);
|
||||
break;
|
||||
}
|
||||
if ( extended == 2 ) break;
|
||||
}
|
||||
n = Getattr(n, "sym:nextSibling");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue