ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Contribution and Coding Style Guide Bullet Physics Library

2021-02-25 09:02:51  阅读:190  来源: 互联网

标签:Style btExampleCodingStyleClass Bullet Coding use header file include software


 

Contribution and Coding Style Guide

 

Bullet Physics Library

 

///Authors: Erwin Coumans and John McCutchan

///Initial version April 4, 2008

///Updated June 3, 2010: Clarified some guidelines

///Updated April 23, 2015: Add more guidelines

///Update March 2017: Explain bracket use

///http://bulletphysics.org

 

See also our clang-format file. You can use the following command to format a file:

 

clang-format -style=file -i path/to/file.cpp


General guidelines:

 

  1. Make sure you are legally allowed to make a contribution under the zlib license

  2. The Zlib license header goes at the top of each source file, with appropriate copyright notice.

  3. After a pull request, check the appveyor and travis status on http://github.com/bulletphysics/bullet3

  4. One class per header file, smaller structures can be combined in a single file.

  5. No use of global variables, singletons, namespaces (except some examples code)

  6. Prefer implementation in a CPP file instead of a header file.

  7. Use only C++2003, (no C++11 yet).

  8. No use of exception handling, no RTTI.

  9. Use tabs instead of multiple spaces. 

  10. Use Doxygen-style comments.

  11. Don't use STL. Bullet provides btAlignedObjectArray to replace std::vector

  12. Make sure memory allocation in the core SDK goes through the central memory allocator

  13. No use of third-party libraries such as BOOST and so on.

  14. Don't include #include <stdio.h> or similar include files in the core SDK. In demos and examples it is ok.

  15. Try to use const when possible

  16. Make sure to comment out printf, used while debugging

  17. Member variables start with m_ and go first at the top of the class declaration

  18. Avoid circular dependencies of classes.

  19. Avoid multiple inheritance.

  20. Use forward declaration whenever possible instead of including other header files

  21. A header file should compile as-is without requiring other header files to be included first

  22. Use btScalar instead of float/double so that Bullet can be compiled as double/single precision

  23. Make sure the code compiles on 32bit and 64bit platforms in single and double precision.

  24. Use CamelCase naming, class names start with bt prefix, variable names start with lower case

  25. Opening brackets start on the next line. Always use brackets, even for one-line if statements.



Please review the following example class implementation and declaration (header file)

 

//Example source file for a class.

--------------------------------------------------------------------------------

/*

Bullet Continuous Collision Detection and Physics Library

Copyright (c) 2003-2015 Erwin Coumans http://bulletphysics.org


This software is provided 'as-is', without any express or implied warranty.

In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,

including commercial applications, and to alter it and redistribute it freely,

subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.

3. This notice may not be removed or altered from any source distribution.

*/

 

///Always include the own class header file first.

///A header file should not rely on any other include files.

///Assume Bullet/src as base include path.

///Don't use relative paths in include file names.

///Don't include the public btBulletDynamicsCommon.h in internal implementation

 

#include "btExampleCodingStyleClass.h"

#include "BulletDynamics/Dynamics/btRigidBody.h"


btExampleCodingStyleClass::btExampleCodingStyleClass()

:m_somePrivateMember(0)

{

}


btExampleCodingStyleClass::~btExampleCodingStyleClass()

{

}


void btExampleCodingStyleClass::someFunctionName(btRigidBody* body)

{

int i;

for (i=0;i<m_somePrivateMember;i++)

{

body->getLinearVelocity();

}


//always use brackets, even for one-liners!

if (i==2)

{

body->getLinearVelocity();

}

}



 

///Example header file for a class.

------------------------------------------------------------------------------


/*

Bullet Continuous Collision Detection and Physics Library

Copyright (c) 2003-2015 Erwin Coumans http://bulletphysics.org


This software is provided 'as-is', without any express or implied warranty.

In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,

including commercial applications, and to alter it and redistribute it freely,

subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.

3. This notice may not be removed or altered from any source distribution.

*/

///

/// Author section: this file was created/modified by FirstName LastName

///

#ifndef _BT_EXAMPLE_CODING_STYLE_CLASS

#define _BT_EXAMPLE_CODING_STYLE_CLASS

#include "LinearMath/btScalar.h"


/// Avoid including headerfiles if possible and use forward declarations instead.

class btRigidBody;


///This btExampleCodingStyleClass is an example to demonstrate coding style.

///It starts with 3 slashes, to help Doxygen.

///Explanation/documentation can be multiline.

///Avoid using /* */ comments in general, except for the license header.

class btExampleCodingStyleClass

{

int m_somePrivateMember;


  btAlignedObjectArray<btRigidBody*> m_bodies;


protected:


btScalar m_someProtectedMember;


public:

btExampleCodingStyleClass();


virtual ~btExampleCodingStyleClass();


///someFunction explanation and comments start with 3 slashes, to help Doxygen

///function names start with lower case

///multiple concatenated words are capitalized

void someFunctionName(btRigidBody* body);


///if the getMember function becomes larger, please move it to the .cpp file

const int getMember() const

{

return m_somePrivateMember;

}

};

#endif //_BT_EXAMPLE_CODING_STYLE_CLASS

 

标签:Style,btExampleCodingStyleClass,Bullet,Coding,use,header,file,include,software
来源: https://www.cnblogs.com/itfanr/p/14444963.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有