Songbird Wiki > Developer Center > Articles > Style Manual > C/C++ Sources and Object Implementation

C/C++ Sources and Object Implementation

From $1

C/C++ Source File

All source files should contain the following elements.

  1. Songbird GPL License
  2. Source File Sections

See an example.

Including Files

All files included from the Mozilla SDK should have angle brackets to contain the filename and should not include any directories. Please alphabetize.

All Songbird files located in the same directory should use quotes to contain the filename. All others (including XPIDL-generated interface headers) should use angle brackets. Please alphabetize.

All operating system files should use angle brackets to contain the filename. Please alphabetize.

Defines

Definitions should have comments indicating their usage.

Class Implementation

The Constructor and Destructor

Constructors and Destructors should use the following pattern:

sbSampleClass::sbSampleClass()
: mData1(null),
  mData2(null),
  mData3(1)
{
  // Construction Code
}

sbSampleClass::sbSampleClass(type aData1,
                             type aData2)
: mData1(aData1),
  mData2(aData2),
  mData3(1)
{
  // Construction Code
}

sbSampleClass::~sbSampleClass()
{
  // Destruction Code
}

Methods

Class methods should use the following pattern:

return_type
sbSampleClass::GetData(type aArg1,
                       type aArg2)
{
  return aArg1 + aArg2;
}

Example Source File

Below is an example C++ source file that meets all the requirements above as well as the documentation requirements.

/*
//
// BEGIN SONGBIRD GPL
// 
// This file is part of the Songbird web player.
//
// Copyright(c) 2006 POTI, Inc.
// http://songbirdnest.com
// 
// This file may be licensed under the terms of of the
// GNU General Public License Version 2 (the "GPL").
// 
// Software distributed under the License is distributed 
// on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either 
// express or implied. See the GPL for the specific language 
// governing rights and limitations.
//
// You should have received a copy of the GPL along with this 
// program. If not, go to http://www.gnu.org/licenses/gpl.html
// or write to the Free Software Foundation, Inc., 
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// 
// END SONGBIRD GPL
//
*/

/** 
* \file sbSample.cpp
* \Sample Implementation.
*/

#include "sbSample.h"

#include <nsAutoLock.h>
#include <nsCRT.h>
#include <nsXPCOM.h>

#define NS_PROFILE_STARTUP_OBSERVER_ID "profile-after-change"
#define NS_PROFILE_SHUTDOWN_OBSERVER_ID "profile-before-change"

NS_IMPL_ISUPPORTS2(sbSample, sbISample, sbIOtherInterface)

sbSample::sbSample()
: mData1(null),
  mData2(-1)
{
}

sbSample::~sbSample()
{
}

NS_IMETHODIMP
sbSample::Initialize()
{
  mData1 = -1;

  return NS_OK;
}
Tags:
 
Images (0)
 
Comments (0)
You must login to post a comment.