style
.pdf3.Saks, Dan, and Tom Plum. C++ Programming Guidelines. //Cardiff, NJ: Plum Hall, 1991.
4.Meyers, Scott. Effective C++. // MA: Addison-Wesley, 1992.
5.Murray, Rob. C++ Strategies And Tactics. // MA: Addison-Wesley, 1993.
ПРИЛОЖЕНИЕ 1: ВЕНГЕРСКАЯ НОТАЦИЯ
Prefix |
|
Type |
Description |
Example |
|||
Basic Types |
|
|
|
|
|
||
ch, c |
|
Char |
|
8-bit character |
|
ChGrade |
|
sz, str |
|
char[] |
|
8-bit string |
|
szBuffer[] |
|
s |
|
Short |
|
16-bit signed integer |
|
sIndex |
|
n, I |
|
int |
|
Integer (size dependent on |
|
nLength |
|
|
|
|
|
operating system) |
|
|
|
u |
|
unsigned |
|
Unsigned integer (size de- |
|
uSize |
|
|
|
|
|
pendent on operating system) |
|
|
|
l |
|
long |
|
32-bit signed integer |
|
lSum |
|
ul |
|
usigned |
|
32-bit unsigned integer |
|
ulFreeSpac |
|
|
|
long |
|
|
|
e |
|
flt |
|
float |
|
Floating point |
|
fltResult |
|
dbl |
|
double |
|
|
|
DblResult |
|
ldbl |
|
long double |
|
|
ldblResult |
||
Aliased |
Types |
|
|
|
|
|
|
by |
|
BYTE |
|
Byte (unsigned char) |
|
byLower |
|
b |
|
BOOL |
|
Boolean value |
|
bEnabled |
|
n, u |
|
UINT |
|
Unsigned value (size de- |
|
nLength |
|
|
|
|
|
pendent on operating system) |
|
|
|
w |
|
WORD |
|
16-bit unsigned value |
|
wPos |
|
l |
|
LONG |
|
32-bit signed integer |
|
lOffset |
|
dw |
|
DWORD |
|
32-bit unsigned integer |
|
dwRange |
|
h |
|
handle |
|
Handle to Windows object |
|
hWnd |
|
Pointers |
|
|
|
|
|
|
|
p |
|
void* |
|
Ambient memory model |
|
|
pDoc |
|
|
|
|
pointer |
|
|
|
pp |
|
void** |
|
Pointer to pointer |
|
|
ppDoc |
lp |
|
FAR* |
|
Far pointer |
|
|
lpDoc |
np |
|
NEAR* |
|
Near pointer |
|
|
npDoc |
lpsz |
|
LPSTR |
|
32-bit pointer to character |
|
|
lpszName |
|
|
|
|
string |
|
|
|
lpfn |
|
callback |
|
Far pointer to CALLBACK |
|
|
lpfnAbort |
41
Prefix |
|
Type |
Description |
Example |
||
|
|
|
|
function |
|
|
p(type- |
|
basic_type |
Pointer to basic type variable |
|
|
|
prefix) |
|
* |
|
|
|
|
Derived |
Types |
|
|
|
|
|
pt |
|
POINT |
|
Points |
|
ptCurPos |
rc |
|
RECT |
|
Rectangle |
|
rcViewPort |
Obj |
|
OBJECT |
|
Object |
|
objOld |
Arr |
|
ARRAY |
|
Array |
|
arrItems |
ПРИЛОЖЕНИЕ 2: ПРИМЕРЫ ИСХОДНЫХ И ЗАГОЛОВОЧНЫХ ФАЙЛОВ
/****************************************************************
\
FILE..........: abrfname.cpp AUTHOR........: Dmitriy Viktorov
DESCRIPTION...: The module contains function for getting an Abbreviate file name from given name.
FUNCTIONS.....: AbbreviateFileName(), GetFileName() SWITCHES......: WIN32 - if defined, 32-bit version is
compiled, otherwise 16-bit edition is compiled. _UNICODE - if defined, UNICODE support is provided.
COPYRIGHT.....: Copyright (c) 1996-97, Arcadia Inc. HISTORY.......: DATE COMMENT
-------- --------------------------------------
-
12-23-96 Created - Dmitriy
02-12-97 Fixed bug with long file names – Sergey
\****************************************************************
/
/*===============================[ |
|
SPECIAL |
]====================*/ |
|
|
#define STRICT |
|
|
/*===============================[ |
IMPORT |
DECLARATIONS |
]===+====*/ |
|
|
#include "windows.h" |
|
|
/*===============================[ |
PUBLIC |
DECLARATIONS |
]========*/ |
|
|
#include "abrfname.h" |
|
|
42
/*===============================[ |
PRIVATE |
DECLARATIONS |
|
]=======*/ |
|
|
|
/*===============================[ |
..PRIVATE |
CONSTANTS |
|
]========*/ |
|
|
|
const TCHAR cNull |
= _T('\0'); |
|
|
const TCHAR cRSlash |
= _T('/'); |
|
|
const TCHAR cLSlash |
= _T('\\'); |
|
|
const TCHAR cColon |
= _T(':'); |
|
|
/*===============================[ |
..PRIVATE |
FUNCTIONS |
|
]========*/ |
|
|
|
UINT PASCAL GetFileName(LPCTSTR lpszPathName, LPTSTR lpszTitle, UINT nMax);
/*===============================[ ..PRIVATE PSEUDO FUNCTIONS ]=*/
#ifndef _tcsinc #ifdef _WIN32
#define _tcsinc(x) CharNext(x)
#else
#define _tcsinc(x) AnsiNext(x) #endif // _WIN32
#endif
#ifndef _MFC_VER // MFC specific #define ASSERT ((void)0)
#endif
/*================================[ PUBLIC FUNCTIONS]===========*/
/****************************************************************
\
FUNCTION......: AbbreviateFileName
DESCRIPTION...: Makes an abbreviate file name from the given full path name.
ARGUMENTS.....: lpszCanon |
- pointer to a full path name to be |
ichMax |
abbreviated, |
- max number of characters of the |
resultant file name, bAtLeastName - specify whether the file name
should be left at least after abbreviation.
43
RETURNS.......: |
None. |
NOTES.........: |
Below is the example how the function works. |
lpszCanon = C:\MYAPP\DEBUGS\C\TESWIN.C
ichMax bAtLeastName |
Result (lpszCanon) |
|
------ |
------------ |
-------------------------- |
- |
FALSE |
<empty> |
1-7 |
||
1-7 |
TRUE |
TESWIN.C |
8-14 |
x |
TESWIN.C |
15-16 |
x |
C:\...\TESWIN.C |
17-23 |
x |
C:\...\C\TESWIN.C |
24-25 |
x |
C:\...\DEBUGS\C\TESWIN.C |
26+ |
x |
C:\MYAPP\DEBUGS\C\TESWIN.C |
\****************************************************************
/
void |
|
|
PASCAL AbbreviateFileName |
|
|
( |
|
// INOUT |
LPTSTR lpszCanon, |
||
int |
ichMax, |
// IN |
BOOL |
bAtLeastName |
// IN |
) |
|
|
{ |
|
|
int ichFullPath; int ichFileName; int ichVolName;
const TCHAR* lpszCur; const TCHAR* lpszBase; const TCHAR* lpszFileName;
ASSERT(lpszCanon != NULL); if(lpszCanon == NULL)
return;
lpszBase |
= lpszCanon; |
ichFullPath |
= lstrlen(lpszCanon); |
ichFileName |
= GetFileName(lpszCanon, NULL, 0) - 1; |
lpszFileName |
= lpszBase + (ichFullPath - ichFileName); |
//If ichMax is more than enough to hold the full path name,
//we'redone.
//This is probably a pretty common case, so we'll put it
//irst.
if (ichMax >= ichFullPath) return;
//If ichMax isn't enough to hold at least the basename,
//we're done
if (ichMax < ichFileName)
{
44
lstrcpy(lpszCanon, (bAtLeastName) ? lpszFileName : &cNull);
return;
}
//Calculate the length of the volume name. Norm. = two chars
//(e.g., "C:", "D:",etc.), but for a UNC name, it could be
//more (e.g., "\\server\share").
//
// If ichMax isn't enough to hold at least <volume_name>\
...
// \<base_name>, the result is the base filename.
}
/*===============================[ |
PRIVATE |
FUNCTIONS |
]==========*/ |
|
|
/****************************************************************
\
FUNCTION......: GetFileName
DESCRIPTION...: Returns the file name from the given full path name.
ARGUMENTS.....: lpszPathName - pointer to the given full path
name, |
- pointer to a buffer where the |
lpszTitle |
|
nMax |
file name will be placed, |
- max size of the buffer for the |
|
|
resultant file name. |
RETURNS.......: The return value is the number of bytes copied to lpszTitle. If lpszTitle is NULL, the func-
tion
returns the number of bytes enough to hold the file name.
\****************************************************************
/
UINT PASCAL GetFileName |
|
|
( |
|
// IN |
LPCTSTR lpszPathName, |
||
LPTSTR |
lpszTitle, |
// INOUT |
UINT |
nMax |
// IN |
) |
|
|
{ |
|
|
#ifdef _MFC_VER // MFC specific ASSERT(lpszTitle == NULL ||
AfxIsValidAddress(lpszTitle, _MAX_FNAME)); ASSERT(AfxIsValidString(lpszPathName));
#endif
//always capture the complete file name including extension
//(if present)
LPTSTR lpszTemp = (LPTSTR)lpszPathName;
for( LPCTSTR lpsz = lpszPathName; *lpsz != cNull;
45
lpsz =_tcsinc(lpsz))
{
// remember last directory/drive separator if (cLSlash == *lpsz ||
cRSlash == *lpsz || cColon == *lpsz) lpszTemp = (LPTSTR)_tcsinc(lpsz);
}
//lpszTitle can be NULL which just returns
//the number of bytes
if (lpszTitle == NULL)
return (lstrlen(lpszTemp) + 1);
// otherwise copy it into the buffer provided return lstrcpyn(lpszTitle, lpszTemp, nMax);
}
/** (END OF FILE : abrfname.cpp)
*******************************/
/****************************************************************
\
FILE.......... |
: abrfname.h |
|
AUTHOR........ |
: Dmitriy Viktorov |
|
DESCRIPTION... |
: The header file contains AbbreviateFileName |
|
FUNCTIONS |
function declaration. |
|
: AbbreviateFileName() |
||
SWITCHES...... |
: WIN32 |
- if defined, 32-bit version is |
|
compiled, otherwise 16-bit edition is compiled. |
|
|
|
_UNICODE - if defined, UNICODE support is |
COPYRIGHT |
|
provided. |
: Copyright (c) 1996-97, Arcadia Inc. |
||
HISTORY....... |
: DATE |
COMMENT |
|
-------- |
-------------------------------------- |
-
12-23-96 Created - Dmitriy \****************************************************************
/
/*===============================[ |
REDEFINITION |
DEFENCE |
]=======*/ |
|
|
#ifndef ABRFNAME_H |
|
|
#define ABRFNAME_H |
|
|
/*===============================[ |
|
SPECIAL |
]====================*/ |
|
|
#if !defined(_INC_WINDOWS) || !defined(_WINDOWS_)
#error include 'windows.h' before including this file #endif
46
#ifdef WIN32
#include <tchar.h>
#else
#define LPCTSTR LPCSTR #define LPTSTR LPSTR #define TCHAR CHAR #define _T(x)
#endif
/*===============================[ |
|
PUBLIC |
|
FUNCTIONS |
|||
]===========*/ |
|
|
|
|
|
|
|
void PASCAL AbbreviateFileName(LPTSTR lpszCanon, int ichMax, |
|||||||
|
|
|
|
BOOL bAtLeastName); |
|
||
/*===============================[ |
END |
REDEFINITION |
DEFENCE |
||||
]===*/ |
|
|
|
|
|
|
|
#endif /* ABRFNAME_H */ |
FILE |
|
: |
abrfname.h) |
|||
/** |
(END |
OF |
|
||||
*********************************/
47
Евгений Олегович Степанов, Сергей Васильевич Чириков Стиль программирования на C++ Учебное пособие
Компьютерная верстка |
С.В.Чириков |
Дизайн |
С.В.Чириков |
Редакционно-издательский отдел |
СПб ГИТМО(ТУ) |
Зав. РИО |
Н.Ф.Гусарова |
Лизензия ИД N00408 от 05.11.99 |
|
Подписато к печати 06.12.00 |
|
Отпечатано на ризографе Заказ N 292 |
|
Тираж 150 экз. |
|
48
