/** *
* * NOTE: * * This documentation provides information about the programming interface * provided by the PUNC software and a general guide to linking to the PUNC * libraries. Information about installation, configuration, and general usage * can be found in the User's Guide. *
* PUNC * (Portable Understructure for Numerical Computing) was written by * Michael Holst * at Caltech and UC San Diego, primarily as a portability layer for * FETK * (the Finite Element TookKit). * * \section formalism Clean OO C Formalism * *
* PUNC was written in * Clean OO C, * which is a self-imposed disciplined coding formalism for * producing object-oriented ANSI/Standard C which can be * compiled with either a C or C++ compiler. * We will briefly describe the formalism here * (borrowing from N. Baker's nice description in the APBS documentation). * *
* Clean OO C formalism requires that all public data is * enclosed in structures which resemble C++ classes. These structures and * member functions are then declared in a public header file which provides a * concise description of the interface (or API) for the class. * Private functions and * data are included in private header files (or simply the source code files * themselves) which are not visible generally visible (data encapsulation). * When using the library, the * user only sees the public header file and the compiled library and is * therefore (hopefully) oblivious to the private members and functions. Each * class is also equipped with a constructor and destructor function which is * responsible for allocating and freeing any memory required by the * instatiated objects. * *
* Public data members are enclosed in C structures which * are visible to the library user. Public member functions are generated by * mangling the class and function names and passing a pointer to the * object on which the member function is supposed to act. For example, a * public member function with the C++ declaration *
* public double Foo::bar(int i, double d) ** would be declared as *
* VEXTERNC double Foo_bar(Foo *thee, int i, double d) ** where
VEXTERNC is a compiler-dependent macro, the underscore
* _ replaces the C++ double-colon ::, and
* thee replaces the this variable implicit in all
* C++ classes. Since they do not appear in public header files, private
* functions could be declared in any format pleasing to the user, however, the
* above declaration convention should generally be used for both public and
* private functions. Within the source code, the public and private function
* declarations/definitions are prefaced by the macros VPUBLIC and
* VPRIVATE, respectively. These are macros which reduce global
* name pollution, similar to encapsulating private data withing C++ classes.
*
* * The only C++ functions not explicitly covered by the above declaration * scheme are the constructors (used to allocate and initialize class data * members) and destructors (used to free allocated memory). These are * declared in the following fashion: a constructor with the C++ declaration *
* public void Foo::Foo(int i, double d) ** would be declared as *
* VEXTERNC Foo* Foo_ctor(int i, double d) ** which returns a pointer to the newly constructed
Foo object.
* Likewise, a destructor declared as
* * public void Foo::~Foo() ** in C++ would be *
* VEXTERNC void Foo_dtor(Foo **thee) ** in Clean OO C. *
* Finally, inline functions in C++ are simply treated as macros in Clean OO C * and declared/defined using "#define" statements in the public * header file. * See any of the PUNC header files for more examples on the Clean OO C * formalism. * * \section style Coding Style * *
* The best (and most entertaining) description of a C coding style that is * very close to what I use in PUNC is that described by Linus Torvalds in his * "CodingStyle" file in the Linux kernel sources (usually found in the file * "/usr/src/linux/Documentation/CodingStyle" on any Linux box). He describes * a coding style that is modular, completely documented (but in a spartan way), * and very practical. * *
* Below are some additional notes on the coding style * I use in PUNC beyond what Torvalds describes. * These additional guidelines * are mostly concerned with being compatible with the Clean OO C dialect, * giving an object-oriented look and feel to PUNC. *
* Use ONLY SPACES, NO TABS, in source code. * When indenting a code block, ALWAYS USE EXACT 4 SPACES, * no more, no less. While this single anal rule seems * excessive, in my experience it is the single most useful * code formatting guideline one can impose, in terms of * producing code written by many different developers that * can be read and understood quickly by other developers * using the same convention. If four spaces (rather than * two or three) forces you to use more than 80 columns for * nesting loops/etc, then your routine is too complex to * be read by someone else anyway and it should be split * into two or more routines. *
*
* "#define" VTRUE 1 * "#define" VFALSE 0 * "#define" VABS(x) ((x) >= 0 ? (x) : -(x)) **
*
* C++: class Mesh { ... };
* Mesh(void) { ... }
* ~Mesh(void) { ... }
*
* Clean C: typedef struct Mesh { ... } Mesh;
* void Mesh_ctor(Mesh *thee) { ... }
* void Mesh_dtor(Mesh *thee) { ... }
*
* NOTE: The "this" pointer is implicitly used in C++. We
* simulate this coding style with the "thee" pointer
* in Clean C. By using a name different than "this",
* we continue to have a legal C++ program.
* *
*
* C++: Class Mesh {
* ...
* void print(void) { ... }
* ...
* }
* void Mesh::plot(void) { ... }
*
* Clean C: void Mesh_print(Mesh *thee) { ... }
* void Mesh_plot(Mesh *thee) { ... }
*
* * I don't always adhere to this, but it helps make * it clear when you are doing something unsafe with * private data that you should have written an accessor * member function to handle. (UPDATE: I no longer allow * this practice in PUNC, because symbols beginning with * an underscore often conflict with internal compiler * symbols in GCC and other ANSI-C compilers.) *
* Beyond the stuctures used to define classes, only standard * datatypes are used as primitive types in PUNC, such as * char, int, float, and double. *
*
*
* if (cond)
* {
* }
*
* whereas I find the following usually more readable:
*
* if (cond) {
* }
*
* However, for complete routines I do follow
* Richard's approach:
*
* void func(void)
* {
* ...stuff...
* }
*
* If something is very simple then I break all rules:
*
* int myId(void) { return id; }
*
* * The API documentation for this code was generated by * doxygen. You can either view the API * documentation by using the links at the top of this page, or the slight * re-worded/re-interpreted list below: *
* * @section license License * @verbatim PUNC = < Portable Understructure for Numerical Computing > Copyright (C) 1994-- Michael Holst