C++ Coding Standards and Style Guide
C++ Coding Standards and Style Guide
1 Introduction
1.I Purpose
1.2 Audience
1.3 Interpretation
2 Names
2.1 Class Names
Class Library Names
Class Instance Names
MethodlFunction Names
MethodIFunction Argument Names
Namespace Names
Variables
2.7.1 Pointer Variables
2.7.2 Reference Variables
2.7.3 Global Variables
Type Names
Enum Type Names and Enum Names
Constants I#define
Structure Names
C Function Names
C++ File Names
Generated Code File Names
3 Formatting
3.1 Variables
3.2 Brace
3.3 Parentheses ()
3.4 Indentation
3.5 Tab I Space
3.6 Blank Lines
3.7 MethodIFunctionArguments
3.8 If IIf else
3.9 Switch
3.10 For 1While
3.11 Break
3.12 Use of goto
3.13 Useof?:
3.14 Return Statement
3.15 Maximum Characters per Line
4 Documentation
4.1 Header File Prolog
4.2 Header File Pure Virtual MethodIFunction Prolog
4.3 Source File Prolog
4.4 Source File MethodIFunction Prolog
4.5 Comments in General
5 Class
5.1 Class Declaration (Header File)
5.1.I Required ~ e t h o d sfor a Class
5.1.2 Class MethodIFunction Declaration Layout
5.1.3 Include
5.1.4 lnlining
5.1.5 Class Header File Layout
6 Templates
7 Prosram Files
9 Efficiencv
10 Miscellaneous
10.1 Extern Statements IExternal Variables
10.2 Preprocessor Directives
10.3 Mixing C and C++
10.4 CVS Keywords
10.5 README file
10.6 Makefiles
10.7 Standard Libraries
10.8 Use of Namespaces
10.9 Standard Template Library (STL)
10.10 Using the new Operator
This document is based on the "C Style Guide" (SEL-94-003). It contains recommendations for
C++ implementations that build on, or in some cases replace, the style described in the C style
guide. Style guidelines on any topics that are not covered in this document can be found in the "C
Style Guide." An attempt has been made to indicate when these recommendationsare just
guidelines or suggestions versus when they are more strongly encouraged.
Using coding standards makes code easier to read and maintain. General principles that
maximize the readability and maintainability of C++ are:
1.1 Purpose
This document describes the Mission Applications Branch's recommended style for writing C++
programs, where code with "good style" is defined as that which is
Organized
Easy to read
Easy to understand
Maintainable
Efficient
1.2 Audience
This document was written specifically for programmers in the Mission Applications development
environment, although the majority of these standards are generally applicable to all environments.
This document is intended to help programmers to produce better quality C++ programs by
presenting specific guidelines for using language features.
1.3 Interpretation
This document provides guidelines for organizing the content of C++ programs and files. The
guidelines are intended to help programmers write code that can be easily read, understood, and
maintained. This document also discusses how C++ code can be written more efficiently.
When confronted with a situation where you could use all upper case abbreviation, you can
do so; or instead, you can use an initial upper case letter followed by all lowercase letters.
The developer should be consistent in how helshe does this.
class FOVPanel
class UtcDate
openDVDPlayer 0 ;
exportHtmlSource0;
InertialReferenceUnit theIRU;
Finesunsensor theFss;
A GUI component class name should be suffixed by the parent component name.
class MainFrarne : public Frame
class Displaypanel : public Panel
When few components of a namespace are used in a file, the code should avoid using
'using' clauses and should use the scope operator instead; however, when there are
I::'
" IsIHaslCan - to ask a question about something and return boo1 type
SetlGet - to setlget a value
O Initialize - to initialize an object
" Compute - to compute something
When coding from the formal specification, match names with the spec but use no
underscores.
When passing a class, an argument can have the same name as its type. This is not
required, however, and in some cases may even be cumbersome. In that case, the name
should be succinct.
void SetForceModel(ForceModel *forceModel)
void SetForceModel(ForceModel *fm)
When coding from a formal specification, match argument names with the spec if possible
but use no underscores.
namespace GmatTimeUtil
2.7 Variables
Variables should begin with a lowercase letter, with the first letter of each word (after the
first) in the name capitalized.
double flatteningcoefficient;
Mavector3 initialposition;
Add a comment to a variable declaration if the meaning is not clear from the variable name.
Internal variables should be declared at the level at which they are needed. For example, if
a variable is used throughout the procedure, it should be declared at the top of the
procedure. If a variable is used only in a computational block, for example, it may be
declared at the top of that block.
Internal variable declarations should be commented well, if their meaning is not clear from
the variable names (particularly useful is a comment about units; units may be included in
the variable name as well, e.g. i n i t i a l ~ o s i t i o n ~ n ~ m )
The declaration of indices may be inside a for loop or above it. (If that variable is needed
after the execution of the loop, it will need to be declared above, not inside, it.)
It is preferable to use the project-definedtypes instead of the built-in types for the loop
indices (e.g. use Integer instead of int).
Place the '*'with the variable name rather than with the type:
MAB::String *name = new MAB::String;
MAB::String *namel, address; / / note, only name1 is a p o i n t e ~
Take care using pointer conversions, particularly conversion from a base type to a derived
type
For Portability
For a null pointer, use "NULL".
Put the '&'with the variable name rather than with the type.
For class overloaded operators and methods returning a reference, put the '&' with the
type.
const Mastring& operator= (const GSSString hgssstring);
const Mastring& operator= (const char *string);
const Masstring& operator= (char ch);
char& operator[l(unsigned int index);
const MaVector3& Normalize();
Type names should have the first letter of each word capitalized.
Enum names should be declared using all caps and underscores between words.
enum DayName {SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY};
enum Colors {RED = 3; BLUE, DARK-BLUE, GREEN, DARK-GREEN, YELLOW = 7 ) ;
The use of #define statements should be avoided. const variables or enumeration types
should be used instead of constant macros. (An exception is when conditional debug is
included - #define statements may be used then).
use
const unsigned int MAX-NUMBER-OF-FILES = 4;
instead of
#define MAX-NUMBER-OF-FILES 4
Use of classes is preferred to structs. However, if all data is public, a struct may be used.
The developer may use structs to encapsulate global data (including exceptions)
struct AttitudeTypes
I
static const RealType TEST-ACCURACY; / / value is 1.192092903-07B
1;
There should be very few C functions used in a C++ program. They should just be used to
interface between C++ and C code.
2.13 C++ File Names
All C++ header files should have the suffix of .hpp
Header files which contain code that is accepted by both C and C++ compilers should have
the file name extension ".h".
With the exception of the .hpp or .cpp suffix, file names should match, as much as
possible, the name of the class declared or defined within it.
3 Formatting
Use of standard formatting makes code easier to read. The general principles for formatting
various kinds of statements are as follows:
Use blank lines to organize statements into paragraphs and to separate logically related
statements.
Limit the complexity of statements - break a complex statement into several simple
statements if it makes the code clearer to read.
3.1 Variables
It is preferable to declare only one variable per line in the code.
3.2 Brace ()
Braces should be used for all blocks. The first brace should appear on the following line,
lined up with the keyword.
10
statementl;
statement;!;
class SolarSystemBody
I
statementl;
statement;!;
...
3;
3.3 Parentheses ()
Always put ( ) around a condition.
3.4 Indentation
Use three or four spaces (3 is strongly suggested) for optimum readability and
maintainability.
When the standard spaces indentation is unworkable, use some logical spacing.
When there are several variable declarations listed together, line up the variables.
in t initialByteCount = MINIMUM-NUMBER-OF-BYTES;
Earth theEarth;
ClientProvidedAngularVelocity clientProvidedAngularVelocity;
Matrix33 m;
exp(2, x)
for (i = 0; i c n; ++i)
if ( )
while ( )
If the argument lists are still too long to fit on the line, you may line up the arguments with
the method name instead.
3.8 If / If else
Indent statements one level using braces. For a single statement use of braces is optional.
if (condition)
statement;
else if (condition)
statement;
else
statement;
if (condition)
C
statement 1;
statement 2;
0 . .
1
else if (condition)
C
statement 1;
statement 2;
.. .
1
else
I
statement;
1
use
if (thepile-sEndOfData0 I = true)
instead of
3.9 Switch
a All switch statements should have a default case, which may be merely a "fatal error" exit.
The default case should be last and does not require a break, but it is a good idea to put
one there anyway for consistency.
Falling through a case statement into the next case statement shall be permitted as long as
a comment is included.
Use the following format for switch statements: If you need to create variables put all code
in a block
switch (expression)
C
case aaa:
statement [sl
break;
case ccc:
C
int v;
statement [sl
break;
1
default:
statement [sl
break;
1
for (condition)
statement;
for (condition)
{
statementl;
statementz;
while (condition)
{
statement [sl
1
3.1 1 Break
A break statement can be used to exit an inner loop of a for, while, do, or switch statement
at a logical breaking point rather than at the loop test.
while (condition)
{
while (condition)
C
if (condition)
I
break;
3.13 Use of ?:
Conditional statements are fine as long as they are not too complex.
(condition)
? long statementl
: long statement2;
3 For Efficiency
ocumentation
Class Users
Class lmplementorslMaintainers
Judiciously placed comments in the code can provide information that a person could not discern
simply by reading the code. Comments can be added at many different levels.
At the program level, you can include a README file that provides a general description of
the program and explains its organization.
At the file level, include a file prolog that explains the purpose of the file and provides
other information.
In the header file, include a method prolog for all pure virtual methods. Add useful
comments for class implementators and maintainers.
In the source file, include a method prolog for all methods, other than pure virtual ones.
Add useful comments for class implementators and maintainers.
Throughout the file, where data are being declared or defined, it is helpful to add comments
to explain the purpose of the variables.
Use of automated process to extract comments from the code can save developers time in
generating documentation. Use Doxygen htt~:llwww.doxvaen.orgto automatically extract
comments from the code and make it available on line for everyone to use. Any comments to be
included in the documentation should follow the JavaDoc convention to mark a comment block.
Set JAVADOC-AUTOBRIEF = YES in the Doxygen configuration file. If JAVADOC-AUTOBRIEF
is set to YES in the configuration file, then JavaDoc style comment blocks will automatically start a
brief description which ends at the first dot followed by a space or new line. The detailed
descriptions follow after. (See Appendix B for commonly-used Doxygen commands)
/**
* brief description.
* detailed description.
/
You may use the following for a brief one line description:
/ / / one l i n e b r i e f d e s c r i p t i o n
Remember that comments beginning with 'I/' will NOT show up in the docuementation.
PDL should not appear at the file level - it should be replaced by well-documented code.
Since the main audience for the header is a user of the class (or utilities) and someone
who may want to derive a class from this one, note any assumptions.
Header file prolog should contain the following sections: Since GMAT uses CVS to control
source code, change history section should not be kept. There is no reason to clutter up
source files with duplicate information which is available from CVS.
CCVS Keyword>
<Class Name Banner> [for a class header]
<Project Name>
<Legal Tag>
<Author>
<Created>
<Class Description>
<Note> - optional
- The <CVS Keyword> should have:
- The <Class Name Banner> is the name of the class in the following form (include the
namespace name, if applicable):
//--------------------------------------------------------------------------
// class Name
//--------------------------------------------------------------------------
- The <Class Description> should include general description of the class. Use the
JavaDoc convention for marking a comment block.
/**
* class description.
*/
- The <Note> section should describe any information necessary for users of the class,
including RequirementIFunctionSpecification Reference. This field can be omitted if
there are no notes for the user.
Example:
Since the main audience for the source file is a maintainer, focus commentary on issues
related to development and maintenance of the code.
Source file prolog format is the same as the header file prolog format (see Header File
Prolog section).
Each prolog should describe the methodlfunction clearly and concisely as to its purpose,
inputs, return value (if any), and possible exceptions or abnormal conditions.
- The exception section should list exceptions thrown in the class. This field can be
omitted if no exceptions thrown.
- Notes about the ownership and deletion responsibilitiesfor pointer arguments can be
included in the argument description.
The source file function prolog should contain the following information:
/ / function signature
//------------------------------------------------------------------------------
/**
brief description of this function.
* detailed description of this function if any.
*
Sparam - if applicable
@return - if applicable
* @exception - if applicable
@see - if applicable
@note - if applicable
*/
//-----------------------------
Example:
//------------------------------------------------------------------------------
/ / MAB::Date (IntType year, IntType month, IntType day, IntType hour,
// IntType minute, RealType second)
//------------------------------------------------------------------------------
/**
* A constructor.
* Constructs objects with split calendar format date and time.
*
* w a r a m <year> input year
* Sparam <month> input month of year
* Sparam <day> input day of month
* Sparam <hour> input hour
* Sparam <minute> input minute
* Sparam <second> input second
* @exception
TimeRangeError when a date or time is out of the specified
*/ range
//-----------------------------------------------------------------------
MAB::Date::MAB::Date (IntType year, IntType month, IntType day, IntType hour.
IntType minute, RealType second)
C
Do not include Program Design Language (PDL). Instead, care should be taken to
clearly, yet succinctly comment the code. i.e. put a block comment before each major
section of code, document variable declarations where needed, refer the reader to
specifications or documents for further information if appropriate, etc.
Include units in comments for variable declarations, if units are not included in the variable
name.
Example:
In particular, when coding from a formal specifications document, make sure to include the
reference in the file prolog; and if coding a specific algorithm, include a reference to the
source of the algorithm in the function prologlepilog (and possibly in the file prologs as
well).
It is also useful when coding from a formal specification, to include commentary, at each
step, specifying the step number or brief description from the specifications (this makes it
easier for code-readers to follow). However, comments should not be too verbose or
restate the obvious.
Example
5 Class
Provide access methods (GetISet) for data as needed for access by other classes or code
(e.g., GetPosition(), SetRadiusO)
Declare a destructor to be virtual if there is any possibility that a class could be derived
from this class (particularly if there are any virtual methods declared for this class).
Declare a method to be virtual only if necessary (as virtual functions are less efficient).
When declaring a function, put its return type on the same line as the function name.
However, if the return type is very long, it is preferable to put the method name on the next
line, lined up with the list of methods.
int GetParamCount 0 ;
...
/ / class definition or type definitions (etc.)
...
#endif / / AnalyticalModel-hpp
- default constructor
- copy constructor
- destructor
- assignment operator
Example:
class SolarSystemBody
{
public:
protected:
private:
0 . .
1;
3 Notes:
" This guideline may be ignored in cases of optimization, where the C library routines are
proved to be more efficient than the C++ library routines)
For system Include files, put a comment explaining why a particular file was included.
Header files should be included only where they are needed and whenever they are
needed for clarity. i.e. the user should be able to easily follow the code to determine the
origin of methods or variables used in the code.
Wherever possible, extern declarations (of global data) should be contained in source files
instead of header files.
Use extern " C if referencing C external variables for functions, when necessary.
When extern data or constants are included in a header file, remember to compile and link
the .cpp file(s) thatcontain the actual definitions of the constants or externs into your
program.
2 For Portability
You should also avoid using directory names in the include directive, since it is
implementation-definedhow files in such circumstances are found. Most modern compiler
allow relative path names with /as separator, because such names has been standardized
outside the C++ standard, for example in POSIX. Absolute path names and path names
with other separators should always be avoided though.
5.1.4 lnlining
Be careful about inlining. If your compiler has an inlining switch, prefer the use of that to
actually including methods' implementations in the header file. (Also, compilers are not up-
to-speed on compiling when methods are inlined in the header - in some cases, a compiler
will generate a larger program because of this).
lnline member functions can be defined inside or outside the class definition. The second
alternative is recommend. The class definition will be more compact and comprehensible if
no implementation can be seen in the class interface.
class X
{
public :
/ / Not recomended: function definition in class
bool insideclass0 const { return false; }
bool outsideClass0 const;
1;
/ / Rec-ended: function definition outside class
inline bool X::outsideClassO const
{
return true;
1
CVS keyword
Class name banner
Header file prolog
Preprocessor #ifndef command
System include files
Application include files
Constant declarations
Class declaration
Non-member functions (global functions)
Preprocessor #endif command
Example:
//$Header$
//------------------------------------------------------------------------------
// Class Name
//------------------------------------------------------------------------------
/ / Header File Prolog
// . - 0
// ..-
//------------------------------------------------------------------------------
#includes ...
Constant declarations ..
class ClassName
{
public:
protected:
. ..
private:
//-------------------------------------
/ / global declarations
//-------------------------------------
.. .
...
5.2.1 Constructors
Do not do any real work in constructor. Initialize variables and do only actions that can't fail.
Object instantiators must check an object for errors after construction.
Avoid throwing exceptions from constructors.
All member data should be initialized in a constructor, not elsewhere, whenever possible.
5.2.2 Exceptions
Use exceptions for truly exceptional conditions, not for message passing (i.e. use
exceptions when processing cannot continue without user action)
z For Efficiency
Catch exceptions by reference.
The function signature, its return type, and the argument names in the definition
(implementation) should match its declaration (prototype) exactly.
When defining a function's implementation, a long return type may go on a line above the
function name.
int AttitudeModelC1ass::GetModelNumber~)
I
CosineMatrix
CosineMatrix::GetInverseO const
I
3 For Efficiency
Minimize the number of constructorldestructor calls: this means minimize the number of
local objects that are constructed; construct on returning from a method, rather than
creating a local object, assigning to it, and then returning it; pass large objects by const
reference; etc.
Initialize member data in an initialization list. It is necessary that the order of the items in
the initialization list match the order of declaration; also, initialize base class data first (if it is
not already initialized in the base class code)
MaString::MaString(const char *stringl, unsigned int lenl,
const char *string2, unsigned int len2)
lengthD(len1 + len2).
caseSensitiveD(true)
C
- CVS keyword
- Class name banner
- Source file prolog
- Source file method prolog followed by implementation
- Include subunits if any
Example:
//$Header$
//------------------------------------------------------------------------------
// Class Name
//------------------------------------------------------------------------------
/ / Source File Prolog
/ / ..-
//------------------------------------------------------------------------------
//-----------------------------------
/ / public methods
//-----------------------------------
//------------------------------------------------------------------------------
I!
~ ~ ~ ~ ~ ~ ~ ~ ~ f i ~ ~ ~ ~ ~ t ~ ~ d ~ ~ ~ ~ ~ ~ ~ s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s sFrench
// ... I
s s s s(France)
ssssssssssssss
I!----------::--------::::.T:.::.::.:::::::::::-------':-:::::::::::::::::.--------- - --
~ -{Formatted: French (France) 1
// source file method prolog
//------------------------------------------------------------------------------
/ / source file method prolog
// 0 . -
//------------------------------------------------------------------------------
Implementation code ..
...
//------------------------------------------------------------------------------
#include ClassSubunits.cpp / / If there is any
3 Notes:
This should only be necessary for .cpp files containing subunits. When used, they
should take the following form:
...
subunit implementations
. ..
#endif / / Orbitoutput-cpp
6 Templates
Templates are in one respect very similar to an inline function. No code is generated when the
compiler sees the declaration of a template; code is generated only when a template instantiation
is needed.
A function template instantiation is needed when the template is called or its address is taken and
a class template instantiation is needed when an object of the template instantiation class is
declared.
The template specifier for a template class should be placed alone on the line preceding the
"class" keyword or the return type for a function. Template parameters should be in upper case.
/ / template declaration
templatecclass Ts
class ListTemplate
I
public:
T front ( ) ;
/ / template definition
templatecclass T>
T ListTemplatecT>::frontO
I
A big problem is that there is no standard for how code that uses templates is compiled. The
compilers that require the complete template definition to be visible usually instantiate the template
whenever it is needed and then use a flexible linker to remove redundant instantiations of the
template member function. However, this solution is not possible on all systems; the linkers on
most UNIX-systems cannot do this.
A big problem is that even though there is a standard for how templates should be compiled, there
are still many compilers that do not follow the standard. Some compilers require the complete
template definition to be visible, even though that is not required by the standard.
This means that we have a potential portability problem when writing code that uses templates.
=> We recommend that you to put the implementationof template functions in a separate file, a
template definition file, and use conditional compilation to control whether that file is included by
the header file. A macro is either set or not depending on what compiler you use. An
inconvenience is that you now have to manage more files. Only inclusion of the header file should
be needed.
7 Program Fil
Files should all begin with a file prolog (see below).
- A class declaration
- Any global type declarations
- Any exceptions
- Any typedefs
- Any includes for template files
- ENUM type definitions
Organize header files by class (one class declaration per header file) or by logical grouping
of functions (e.g. RealUtilities)
For source files which contain related functions (utilities, for example), follow guidelines for
putting functions in some meaningful order.
8 Portabi
Use ANSIIISO C++ whenever it is available.
When optimizing, some thought must be given to portability issues.
Consider optimizations right from the start, as it is much harder to go back and redesign or
recode later.
9 Efficiency
For efficiency, minimize the number of constructor1destructorcalls: this means minimize
the number of local objects that are constructed; construct on returning from a method,
rather than creating a local object, assigning to it, and then returning it; pass large objects
by const reference; etc.
For efficiency, use exceptions only for truly exceptional conditions, not for message
passing
Use embedded assignments when they are proven to be more efficient than not using
them.
while ((c = getchar()) I = EOF)
{
laneous
Avoid declaring non-static external variables. Variables needed by more than one file
should appear in a .cpp file and be externed in a source file.
#ifndef GMAT-API
#define GMAT-API
#endif
Make the header files work correctly when they are included by both C and C++ files. If
you start including a existing C header in new C++ files, fix the C header file to support
C++ (as well as C), don't just extern -cm { } the C header file.
In C header file:
#ifdef -cplusplus
extern 'C"
{
#endif
int existingcfunctionl (...I ;
int existingCfunction2 (...) ;
#ifdef -cplusplus
1
#endif
Example:
//$Header$
10.6 Makefiles
Makefiles are used on some systems to provide a mechanism for efficiently recompiling
C++ code. With makefiles, the make utility recompiles files that have been changed since
the last compilation. Makefiles also allow the recompilation commands to be stored, so
that potentially long CC commands can be greatly abbreviated.
The makefile
The use of namespaces minimizes potential name clashes in C++ programs and libraries and
eliminates the use of global types, variables, etc.
Clashable names include: external variable names, external function names, top-level class
names, type names in public header files, class member names in public header files, etc. (Class
member names are scoped by the class, but can clash in the scope of a derived class. Explicit
scoping can be used to resolve these clashes.)
It is no longer necessary to have global types, variables, constants and functions if namespaces
are used. Names inside namespaces are as easy to use as global names, except that you
sometimes must use the scope operator. Without namespaces it is common to add a common
identifier as a prefix to the name of each class in a set of related classes.
It is recommended not to place "using namespace" directives at global scope in a header file;
instead place it in a source file. This can cause lots of magic invisible conflicts that are hard to
track since it will make names globally accessible to all files that include that header, which is what
we are trying to avoid. Inside an implementationfile, using declarations and using directives are
less dangerous and sometimes very convenient. On the other hand, too-frequent use of the scope
operator is not recommended. The difference between local names and other names will be more
explicit, but more code needs be rewritten if the namespaces are reorganized.
int someFunction0
{
t rY
//------------------------------------------------------------------------------
// AlDate
//------------------------------------------------------------------------------
/ / GMAT: General Mission Analysis Tool
//
/ / **Legal**
//
/ / Author: Linda Jun
/ / Created: 2003/08/05
//
/**
* This class provides conversions among various ways representing A1 calendar
dates and times.
*/
//------------------------------------------------------------------------------
#ifndef AlDate-hpp
#define AlDate-hpp
//$Header$
//------------------------------------------------------------------------------
// AlDate
//------------------------------------------------------------------------------
/ / GXAT: General Mission Analysis Tool
//
/ / **Legal**
//
/ / Author: Linda Jun
/ / Created: 2003/08/05
//
/**
* This class provides conversions among various ways representing A1 calendar
dates and times.
*/
//------------------------------------------------------------------------------
#include "A1Date.hppN
#include "Time.hppn
#include "Date.hppH
//---------------------------------
/ / public methods
//---------------------------------
//------------------------------------------------------------------------------
/ / AlDateO
//------------------------------------------------------------------------------
/**
* Constructs AlDate objects with 0 second from reference (default constructor).
MAB: :Date0
{
Time t;
*this = t.AlSplit0;
3
//------------------------------------------------------------------------------
/ / AlDate (IntType year, IntType month, IntType day, IntType hour,
// IntType minute, RealType second)
//------------------------------------------------------------------------------
/**
* constructs AlDate objects with split calendar format of date and time.
*
* @param <year> input year in Y Y W .
* @param <month> input month of year.
* @param <day> input day of month.
* @param <hour> input hour.
* @param <minute> input minute.
* @param <second> input second and millisecond in ss.mmm.
*
* $exception TimeRangeError when a date or time is out of the specified range.
* @note Assumes input date is in A1 time system.
*/
//------------------------------------------------------------------------------
A1Date::AlDate (IntType year, IntType month, IntType day, IntType hour,
IntType minute, RealType second)
//------------------------------------------------------------------------------
/ / AlDate (const AlDate &date)
//------------------------------------------------------------------------------
/**
* A copy constructor.
/
//------------------------------------------------------------------------------
A1Date::AlDate (const AlDate &date)
//------------------------------------------------------------------------------
/ / RealType operator- (const AlDate &date) const
//------------------------------------------------------------------------------
/**
* Computes the time offset between two AlDate objects.
*
* @param <date> date object to be subtracted from "this" AlDate object.
*/
//------------------------------------------------------------------------------
RealType A1Date::operator- (const AlDate &date) const
{
RealType offset;
offset = tl - t2;
return offset;
1
//------------------------------------------------------------------------------
/ / AlDate operator= (const AlDate &date)
//------------------------------------------------------------------------------
/**
* Assignment operator.
*
* m a r a m <date> AlDate object whose values to use to set "this" AlDate object.
*
* ereturn AlDate object.
*/
//------------------------------------------------------------------------------
AlDate A1Date::operatore (const AlDate &date)
C
year = date.year;
month = date.month;
day = date.day;
secondsOfDay = date.secondsOfDay;
return *this;
3
//------------------------------------------------------------------------------
/ / RealType ModifiedJulianDate(E1apsedDays jdBias)
//------------------------------------------------------------------------------
/**
* Computes days elapsed since 0 hour of UTC julian date of reference.
* @param cjdBias> offset between modifed julian days and julian days.
*
ereturn A1 modified julian days.
*/
//------------------------------------------------------------------------------
RealType AlDate::ModifiedJulianDate(ElapsedDays jdBias)
{
RealType daysElapsed;
ElapsedDays julianDays;
Below is a list of widely used commands with a description of their arguments. For a full list of
all commands, refer to the Doxygen Documentation Section 21 Special Commands from
htt~://www.stack.nll-dimitrildoxv~en/download.html#latestman.
@author (list of authors) S t a r t s a paragraph where one or more author names may
be entered.
@class <name> [<header-file>l [<header-names1 Indicates that a comment block
contains documentation f o r a c l a s s with name. Optionally a header f i l e and a
header name can be s p e c i f i e d .
Wdate {date description) S t a r t s a paragraph where one or more dates may be
entered.
Bdefgroup <name> (group title) Indicates that a comment block contains
documentation f o r a group o f classes, f i l e s or namespaces.
Bendlink This command ends a l i n k that i s started with the @link command.
@enurn <name> Indicates that a comment block contains documentation f o r an
enumeration.
@example <file-name> Indicates that a comment block contains documentation f o r a
source code example.
Wexception <exception-object> {exception description) S t a r t s an exception
description f o r an exception object with name <exception-object,. Followed b y a
description o f the exception.
@file [<name>] Indicates that a comment block contains documentation f o r a source
or header f i l e with name <name>.
Wfn (function declaration) Indicates that a comment block contains documentation
f o r a function ( e i t h e r global or as a member o f a c l a s s ) .
Binclude <file-name> This command can be used t o include a source f i l e as a block
o f code. The command takes the name o f an include f i l e as an argument.
Winterface <name> Indicates that a comment block contains documentation f o r an
i n t e r f a c e with name <name>.
Blink <link-object> This command can be used t o create a l i n k t o an object (a
f i l e , c l a s s , or member) with a user s p e c i f i e d l i n k - t e x t . The l i n k command should
end with an Bendlink command.
Wname (header) This command turns a comment block i n t o a header d e f i n i t i o n o f a
member group.
h a m e s p a c e <name> Indicates that a comment block contains documentation f o r a
namespace with name <name>.
@package <name> Indicates that a comment block contains documentation f o r a Java
package with name <name>.
@param <parameter-name> (parameter description) S t a r t s a parameter description
f o r a function parameter with name <parameter-name>. Followed b y a description o f
the parameter .
Breturn {description of the return value} S t a r t s a return value description f o r a
function.
Bretval ereturn value> {description) S t a r t s a return value description f o r a
function with name <return value>. Followed b y a description o f the return value.
Wstruct <name> [<header-file>] [<header-name>] Indicates that a comment block
contains documentation f o r a s t r u c t with name <name>.
Wtest {paragraph describing a test case) S t a r t s a paragraph where a t e s t case can
be described.
Wunion <name> [<header-file>] [<header-name>] Indicates that a comment block
contains documentation f o r a union with name <name>.
W a r (variable declaration) Indicates that a comment block contains documentation
f o r a variable or enum value ( e i t h e r global or as a member o f a c l a s s ) .
@version {version number) S t a r t s a paragraph where one or more version s t r i n g s
may b e e n t e r e d .
@warning {warning message) S t a r t s a paragraph where one o r more warning messages
may b e e n t e r e d .
References
1. "C Style Guide", Doland, J. et. al., SEL-94-003, Software Engineering Laboratory Series,
Goddard Space Flight Center, August 1994.
3. C++ Primer, 2nd Edition, Lippman, S., AT&T Bell Laboratories, 1991.
4. "Programming in C++ Rules and Recommendations", Henricson, M. and Nyquist, E., Ellemtel
Telecommunication Systems Laboratories, 1990-1992.
5. C++ Style Guide, Version 1.O, Software and Automation Systems Branch, Goddard Space
Flight Center, July 1992.
6. "C++ Programming Style Guides", Eckel, B., UNlX Review, March 1995.