| 1 | |
| 2 | = RFC 8: Developer Guidelines = |
| 3 | |
| 4 | Author: Frank Warmerdam[[BR]] |
| 5 | Contact: warmerdam@pobox.com[[BR]] |
| 6 | Status: draft |
| 7 | |
| 8 | == Purpose == |
| 9 | |
| 10 | This document is intended to document developer practices for the GDAL/OGR |
| 11 | project. It will be an evolving document. |
| 12 | |
| 13 | == Portability == |
| 14 | |
| 15 | GDAL strives to be widely portable to 32bit and 64bit computing environments. |
| 16 | It accomplishes this in a number of ways - avoid compiler specific directives, |
| 17 | avoiding new, but perhaps not widely available aspects of C++, and most |
| 18 | importantly by abstracting platform specific operations in CPL functions |
| 19 | in the gdal/port directory. |
| 20 | |
| 21 | Generally speaking, where available CPL functions should be used in preference |
| 22 | to operating system functions for operations like memory allocation, |
| 23 | path parsing, filesystem io, multithreading functions, and ODBC access. |
| 24 | |
| 25 | == Variable Naming == |
| 26 | |
| 27 | Much of the existing GDAL and OGR code uses an adapted Hungarian naming |
| 28 | convention. Use of this convention is not manditory, but when maintaining |
| 29 | code using this convention it is desirable to continue adhering to it with |
| 30 | changes. Most importantly, please avoiding using it improperly as that can |
| 31 | be very confusing. |
| 32 | |
| 33 | In Hungarian prefixing the prefix tells something about about the type, and |
| 34 | potentially semantics of a variable. The following are some prefixes used |
| 35 | in GDAL/OGR. |
| 36 | |
| 37 | * '''p''': pointer |
| 38 | * '''a''': array |
| 39 | * '''sz''': zero terminated string (eg." char szName[100];") |
| 40 | * '''psz''': pointer to a zero terminated string. (eg. "char *pszName;") |
| 41 | * '''n''': integer number (size unspecified) |
| 42 | * '''i''': integer number used as a zero based array or loop index. |
| 43 | * '''f''': floating point value (single precision) |
| 44 | * '''df''': floating point value (double precision) |
| 45 | * '''o''': c++ object |
| 46 | * '''os''': CPLString |
| 47 | * '''h''': an opaque handle (such as GDALDatasetH). |
| 48 | |
| 49 | Prefix can be stacked. The following are some examples of meaningful |
| 50 | variables. |
| 51 | |
| 52 | * '''char **papszTokens''': Pointer to an array of strings. |
| 53 | * '''int *panBands''': Pointer to an array of numbers. |
| 54 | * '''double *padfScanline''': Pointer to an array of doubles. |
| 55 | * '''double *pdfMeanRet''': Pointer to a single double. |
| 56 | * '''GDALRasterBand *poBand''': Pointer to a single object. |
| 57 | |
| 58 | It may also be noted that the standard convention for variable names |
| 59 | is to capitalize each word in a variable name. |
| 60 | |
| 61 | == Headers, and Comment Blocks == |
| 62 | |
| 63 | == Misc. Notes == |
| 64 | |
| 65 | * Use lower case filenames. |
| 66 | * Use .cpp extension for C++ files (not .cc). |
| 67 | * Avoid spaces or other special characters in file or directory names. |
| 68 | * Use 4 character indentation levels. |
| 69 | * Use spaces instead of hard tab characters in source code. |
| 70 | * Try to keep lines to 79 characters or less. |
| 71 | |