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.

VISUAL C++<br />

method, use the smart pointer “&” dereference operator. This will cause the<br />

previous interface pointer in the smart pointer to be released. The smart pointer is<br />

then populated with the new [out] value. The implementation of the method will<br />

have already incremented the object reference count. This will be released when<br />

the smart pointer goes out of scope:<br />

{<br />

IFooPtr ipFoo1, ipFoo2;<br />

ipFoo1.CreateInstance(CLSID_Foo);<br />

ipFoo2.CreateInstance(CLSID_Foo);<br />

// Initialize ipBar Smart pointer from Foo1.<br />

IBarPtr ipBar;<br />

ipFoo1->get_Bar(&ipBar);<br />

// The "&" dereference will call Release on ipBar.<br />

// ipBar is then repopulated with a new instance of IBar.<br />

ipFoo2->get_Bar(&ipBar);<br />

}<br />

// ipBar goes out of scope, and the smart pointer destructor calls Release.<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 a separate line:<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 />

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

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

Saved successfully!

Ooh no, something went wrong!