18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

C++ APPLICATION PROGRAMMING INTERFACE<br />

Here are some suggestions for a naming<br />

convention. These help identify the variable’s<br />

usage and type and thus reduce coding errors.<br />

This is an abridged Hungarian notation:<br />

Prefix<br />

m<br />

c<br />

g<br />

<br />

Prefix<br />

b<br />

by<br />

cx/cy<br />

d<br />

dw<br />

f<br />

fn<br />

h<br />

i<br />

ip<br />

l<br />

p<br />

s<br />

sz<br />

w<br />

x, y<br />

[_]<br />

Variable scope<br />

Instance class members<br />

Static class member (including constants)<br />

Globally static variable<br />

local variable or struct or public class<br />

member<br />

<br />

Data Type<br />

Boolean<br />

byte or unsigned char<br />

short used as size<br />

double<br />

DWORD, double word or unsigned long<br />

float<br />

function<br />

handle<br />

int (integer)<br />

smart pointer<br />

long<br />

a pointer<br />

string<br />

ASCIIZ null-terminated string<br />

WORD unsigned int<br />

short used as coordinates<br />

describes how the variable is used or<br />

what it contains. The and <br />

portions should always be lowercase, and the<br />

should use mixed case:<br />

Variable Name<br />

m_hWnd<br />

ipEnvelope<br />

m_pUnkOuter<br />

c_isLoaded<br />

g_pWindowList<br />

Description<br />

a handle to HWND<br />

a smart pointer to a COM interface<br />

a pointer to an object<br />

a static class member<br />

a global pointer to an object<br />

Naming conventions<br />

Type names<br />

All type names (class, struct, enum, and typedef) begin with an uppercase letter and<br />

use mixed case for the rest of the name:<br />

class Foo : public CObject { . . .};<br />

struct Bar { . . .};<br />

enum ShapeType { . . . };<br />

typedef int* FooInt;<br />

Typedefs for function pointers (callbacks) append Proc to the end of their names.<br />

typedef void (*FooProgressProc)(int step);<br />

Enumeration values all begin with a lowercase string that identifies the project; in<br />

the case of ArcObjects this is esri, and each string occurs on separate lines:<br />

typedef enum esriQuuxness<br />

{<br />

esriQLow,<br />

esriQMedium,<br />

esriQHigh<br />

} esriQuuxness;<br />

Function names<br />

Name functions using the following conventions:<br />

For simple accessor and mutator functions, use Get and<br />

Set:<br />

int GetSize();<br />

void SetSize(int size);<br />

If the client is providing storage for the result, use Query:<br />

void QuerySize(int& size);<br />

For state functions, use Set and Is or Can:<br />

bool IsFileDirty();<br />

void SetFileDirty(bool dirty);<br />

bool CanConnect();<br />

Where the semantics of an operation are obvious from the types of arguments,<br />

leave type names out of the function names.<br />

Instead of:<br />

AddDatabase(Database& db);<br />

consider using:<br />

Add(Database& db);<br />

Instead of:<br />

ConvertFoo2Bar(Foo* foo, Bar* bar);<br />

consider using:<br />

Convert(Foo* foo, Bar* bar)<br />

If a client relinquishes ownership of some data to an object, use<br />

Give. If an object relinquishes ownership of some data to a client,<br />

use Take:<br />

Chapter 4 • <strong>Developer</strong> environments • 201

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!