| 1 |
/** @mainpage SG Programmer's Guide |
| 2 |
* |
| 3 |
* <center> |
| 4 |
* SG Programmer's Guide |
| 5 |
* FETK was written by Michael Host.<br> |
| 6 |
* Additional contributing authors are listed in the code documentation. |
| 7 |
* </center> |
| 8 |
* |
| 9 |
* <hr width="100%"> |
| 10 |
* |
| 11 |
* @section toc Table of Contents |
| 12 |
* <ul> |
| 13 |
* <li> @ref intro |
| 14 |
* <li> @ref style |
| 15 |
* <li> @ref api |
| 16 |
* <ul> |
| 17 |
* <li> <a href="modules.html">Modules</a> |
| 18 |
* <li> <a href="annotated.html">Class list</a> |
| 19 |
* <li> <a href="functions.html">Class members</a> |
| 20 |
* <li> <a href="globals.html">Class methods</a> |
| 21 |
* </ul> |
| 22 |
* <li> @ref license |
| 23 |
* </ul> |
| 24 |
* |
| 25 |
* <p> |
| 26 |
* <i> |
| 27 |
* NOTE: |
| 28 |
* </i> |
| 29 |
* This documentation provides information about the programming interface |
| 30 |
* provided by the SG software and a general guide to linking to the SG |
| 31 |
* libraries. Information about installation, configuration, and general usage |
| 32 |
* can be found in the <a href="../../index.html">User's Guide</a>. |
| 33 |
* <hr> |
| 34 |
* |
| 35 |
* \section intro Introduction |
| 36 |
* |
| 37 |
* <p> |
| 38 |
* SG |
| 39 |
* (Socket Graphics) was written by |
| 40 |
* <a href="http://www.scicomp.ucsd.edu/~mholst/">Michael Holst</a> |
| 41 |
* at Caltech and UC San Diego, primarily as a network-enabled OpenGL-based |
| 42 |
* graphics tool for |
| 43 |
* <a href="http://www.fetk.org">FETK</a> |
| 44 |
* (the Finite Element TookKit). |
| 45 |
* |
| 46 |
* \section formalism Clean OO C Formalism |
| 47 |
* |
| 48 |
* <p> |
| 49 |
* SG was written in |
| 50 |
* <a href="../../cooc.html">Clean OO C</a>, |
| 51 |
* which is a self-imposed disciplined coding formalism for |
| 52 |
* producing object-oriented ANSI/Standard C which can be |
| 53 |
* compiled with either a C or C++ compiler. |
| 54 |
* We will briefly describe the formalism here |
| 55 |
* (borrowing from N. Baker's nice description in the APBS documentation). |
| 56 |
* |
| 57 |
* <p> |
| 58 |
* Clean OO C formalism requires that all public data is |
| 59 |
* enclosed in structures which resemble C++ classes. These structures and |
| 60 |
* member functions are then declared in a public header file which provides a |
| 61 |
* concise description of the interface (or API) for the class. |
| 62 |
* Private functions and |
| 63 |
* data are included in private header files (or simply the source code files |
| 64 |
* themselves) which are not visible generally visible (data encapsulation). |
| 65 |
* When using the library, the |
| 66 |
* user only sees the public header file and the compiled library and is |
| 67 |
* therefore (hopefully) oblivious to the private members and functions. Each |
| 68 |
* class is also equipped with a constructor and destructor function which is |
| 69 |
* responsible for allocating and freeing any memory required by the |
| 70 |
* instatiated objects. |
| 71 |
* |
| 72 |
* <p> |
| 73 |
* Public data members are enclosed in C structures which |
| 74 |
* are visible to the library user. Public member functions are generated by |
| 75 |
* mangling the class and function names and passing a pointer to the |
| 76 |
* object on which the member function is supposed to act. For example, a |
| 77 |
* public member function with the C++ declaration |
| 78 |
* <pre> |
| 79 |
* public double Foo::bar(int i, double d) |
| 80 |
* </pre> |
| 81 |
* would be declared as |
| 82 |
* <pre> |
| 83 |
* VEXTERNC double Foo_bar(Foo *thee, int i, double d) |
| 84 |
* </pre> |
| 85 |
* where <code>VEXTERNC</code> is a compiler-dependent macro, the underscore |
| 86 |
* <code>_</code> replaces the C++ double-colon <code>::</code>, and |
| 87 |
* <code>thee</code> replaces the <code>this</code> variable implicit in all |
| 88 |
* C++ classes. Since they do not appear in public header files, private |
| 89 |
* functions could be declared in any format pleasing to the user, however, the |
| 90 |
* above declaration convention should generally be used for both public and |
| 91 |
* private functions. Within the source code, the public and private function |
| 92 |
* declarations/definitions are prefaced by the macros <code>VPUBLIC</code> and |
| 93 |
* <code>VPRIVATE</code>, respectively. These are macros which reduce global |
| 94 |
* name pollution, similar to encapsulating private data withing C++ classes. |
| 95 |
* |
| 96 |
* <p> |
| 97 |
* The only C++ functions not explicitly covered by the above declaration |
| 98 |
* scheme are the constructors (used to allocate and initialize class data |
| 99 |
* members) and destructors (used to free allocated memory). These are |
| 100 |
* declared in the following fashion: a constructor with the C++ declaration |
| 101 |
* <pre> |
| 102 |
* public void Foo::Foo(int i, double d) |
| 103 |
* </pre> |
| 104 |
* would be declared as |
| 105 |
* <pre> |
| 106 |
* VEXTERNC Foo* Foo_ctor(int i, double d) |
| 107 |
* </pre> |
| 108 |
* which returns a pointer to the newly constructed <code>Foo</code> object. |
| 109 |
* Likewise, a destructor declared as |
| 110 |
* <pre> |
| 111 |
* public void Foo::~Foo() |
| 112 |
* </pre> |
| 113 |
* in C++ would be |
| 114 |
* <pre> |
| 115 |
* VEXTERNC void Foo_dtor(Foo **thee) |
| 116 |
* </pre> |
| 117 |
* in Clean OO C. |
| 118 |
* <p> |
| 119 |
* Finally, inline functions in C++ are simply treated as macros in Clean OO C |
| 120 |
* and declared/defined using "#define" statements in the public |
| 121 |
* header file. |
| 122 |
* See any of the SG header files for more examples on the Clean OO C |
| 123 |
* formalism. |
| 124 |
* |
| 125 |
* \section style Coding Style |
| 126 |
* |
| 127 |
* <p> |
| 128 |
* The best (and most entertaining) description of a C coding style that is |
| 129 |
* very close to what I use in SG is that described by Linus Torvalds in his |
| 130 |
* "CodingStyle" file in the Linux kernel sources (usually found in the file |
| 131 |
* "/usr/src/linux/Documentation/CodingStyle" on any Linux box). He describes |
| 132 |
* a coding style that is modular, completely documented (but in a spartan way), |
| 133 |
* and very practical. |
| 134 |
* |
| 135 |
* <p> |
| 136 |
* Below are some additional notes on the coding style |
| 137 |
* I use in SG beyond what Torvalds describes. |
| 138 |
* These additional guidelines |
| 139 |
* are mostly concerned with being compatible with the Clean OO C dialect, |
| 140 |
* giving an object-oriented look and feel to SG. |
| 141 |
* <ul> |
| 142 |
* <li> |
| 143 |
* Tabs and spaces ==> Probably the most important rule: NO TABS! |
| 144 |
* <p> |
| 145 |
* Use ONLY SPACES, NO TABS, in source code. |
| 146 |
* When indenting a code block, ALWAYS USE EXACT 4 SPACES, |
| 147 |
* no more, no less. While this single anal rule seems |
| 148 |
* excessive, in my experience it is the single most useful |
| 149 |
* code formatting guideline one can impose, in terms of |
| 150 |
* producing code written by many different developers that |
| 151 |
* can be read and understood quickly by other developers |
| 152 |
* using the same convention. If four spaces (rather than |
| 153 |
* two or three) forces you to use more than 80 columns for |
| 154 |
* nesting loops/etc, then your routine is too complex to |
| 155 |
* be read by someone else anyway and it should be split |
| 156 |
* into two or more routines. |
| 157 |
* <p> |
| 158 |
* <li> |
| 159 |
* ALLCAPS ==> A "#define"d constant or a macro. Examples: |
| 160 |
* <pre> |
| 161 |
* "#define" VTRUE 1 |
| 162 |
* "#define" VFALSE 0 |
| 163 |
* "#define" VABS(x) ((x) >= 0 ? (x) : -(x)) |
| 164 |
* </pre> |
| 165 |
* <li> |
| 166 |
* UpperMixed ==> Class name, or class constructor or destructor. |
| 167 |
* Examples: |
| 168 |
* <p> |
| 169 |
* <pre> |
| 170 |
* C++: class Mesh { ... }; |
| 171 |
* Mesh(void) { ... } |
| 172 |
* ~Mesh(void) { ... } |
| 173 |
* |
| 174 |
* Clean C: typedef struct Mesh { ... } Mesh; |
| 175 |
* void Mesh_ctor(Mesh *thee) { ... } |
| 176 |
* void Mesh_dtor(Mesh *thee) { ... } |
| 177 |
* </pre> |
| 178 |
* NOTE: The "this" pointer is implicitly used in C++. We |
| 179 |
* simulate this coding style with the "thee" pointer |
| 180 |
* in Clean C. By using a name different than "this", |
| 181 |
* we continue to have a legal C++ program. |
| 182 |
* <p> |
| 183 |
* <li> |
| 184 |
* lowerMixed ==> A class member function or generic function. Examples: |
| 185 |
* <p> |
| 186 |
* <pre> |
| 187 |
* C++: Class Mesh { |
| 188 |
* ... |
| 189 |
* void print(void) { ... } |
| 190 |
* ... |
| 191 |
* } |
| 192 |
* void Mesh::plot(void) { ... } |
| 193 |
* |
| 194 |
* Clean C: void Mesh_print(Mesh *thee) { ... } |
| 195 |
* void Mesh_plot(Mesh *thee) { ... } |
| 196 |
* </pre> |
| 197 |
* <li> |
| 198 |
* _private data ==> Pre-fixed with an underscore, such as: vint _dim. |
| 199 |
* <p> |
| 200 |
* I don't always adhere to this, but it helps make |
| 201 |
* it clear when you are doing something unsafe with |
| 202 |
* private data that you should have written an accessor |
| 203 |
* member function to handle. (UPDATE: I no longer allow |
| 204 |
* this practice in SG, because symbols beginning with |
| 205 |
* an underscore often conflict with internal compiler |
| 206 |
* symbols in GCC and other ANSI-C compilers.) |
| 207 |
* <li> |
| 208 |
* Datatypes ==> Use only standard or compatible datatypes. |
| 209 |
* <p> |
| 210 |
* Beyond the stuctures used to define classes, only standard |
| 211 |
* datatypes are used as primitive types in SG, such as |
| 212 |
* char, int, float, and double. |
| 213 |
* <p> |
| 214 |
* <li> |
| 215 |
* Core structures ==> Refer to headers vel.h and ves.h in the GEM library |
| 216 |
* for examples. |
| 217 |
* <p> |
| 218 |
* <li> |
| 219 |
* Other comments ==> We basically adhere to the GNU coding conventions, |
| 220 |
* except that Richard Stallman recommends (in his GNU |
| 221 |
* Coding Standards paper) writing blocks as follows: |
| 222 |
* <pre> |
| 223 |
* if (cond) |
| 224 |
* { |
| 225 |
* } |
| 226 |
* </pre> |
| 227 |
* whereas I find the following usually more readable: |
| 228 |
* <pre> |
| 229 |
* if (cond) { |
| 230 |
* } |
| 231 |
* </pre> |
| 232 |
* However, for complete routines I do follow |
| 233 |
* Richard's approach: |
| 234 |
* <pre> |
| 235 |
* void func(void) |
| 236 |
* { |
| 237 |
* ...stuff... |
| 238 |
* } |
| 239 |
* </pre> |
| 240 |
* If something is very simple then I break all rules: |
| 241 |
* <pre> |
| 242 |
* int myId(void) { return id; } |
| 243 |
* </pre> |
| 244 |
* </ul> |
| 245 |
* |
| 246 |
* @section api Application programming interface documentation |
| 247 |
* <p> |
| 248 |
* The API documentation for this code was generated by |
| 249 |
* <a href="http://www.doxygen.org">doxygen</a>. You can either view the API |
| 250 |
* documentation by using the links at the top of this page, or the slight |
| 251 |
* re-worded/re-interpreted list below: |
| 252 |
* <ul> |
| 253 |
* <li> <a href="modules.html">Class overview</a> |
| 254 |
* <li> <a href="annotated.html">Class declarations</a> |
| 255 |
* <li> <a href="functions.html">Class members</a> |
| 256 |
* <li> <a href="globals.html">Class methods</a> |
| 257 |
* </ul> |
| 258 |
* |
| 259 |
* @section license License |
| 260 |
* |
| 261 |
@verbatim |
| 262 |
|
| 263 |
SG = < Socket Graphics > |
| 264 |
Copyright (C) 1994-- Michael Holst |
| 265 |
|
| 266 |
This library is free software; you can redistribute it and/or |
| 267 |
modify it under the terms of the GNU Lesser General Public |
| 268 |
License as published by the Free Software Foundation; either |
| 269 |
version 2.1 of the License, or (at your option) any later version. |
| 270 |
|
| 271 |
This library is distributed in the hope that it will be useful, |
| 272 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 273 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 274 |
Lesser General Public License for more details. |
| 275 |
|
| 276 |
You should have received a copy of the GNU Lesser General Public |
| 277 |
License along with this library; if not, write to the Free Software |
| 278 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 279 |
|
| 280 |
@endverbatim |
| 281 |
*/ |