CODE_STYLE.md
Filament largely uses Android's code style, which is significantly different from the Google code style and is derived from the Java code style, but not quite.
The guiding principles of the filament code style and code formatting can be resumed as:
{ at the end of the line;.cpp or .h file must be an empty linefor (int i = 0; i < max; i++) {
}
class Foo {
public:
protected:
private:
};
.h extension.cpp extension.inc extension#include must use fully qualified names#include < > for all public (exported) headers#include " " for private headersinclude foldersrc foldertest folderfoo library must live in a folder named foolibfoo.so
include/foo/FooBar.h
src/FooBar.cpp
src/data.inc
#include <foo/FooBar.h>
#include "FooBarPrivate.h"
constants are uppercase and don't have a prefixglobal variables prefixed with gstatic variables prefixed with sprivate and protected class attributes prefixed with mstatic class attributes prefixed with spublic class attributes are not prefixedextern int gGlobalWarming;
class FooBar {
public:
FooBar(int attributeName, int sizeInBytes)
: mAttributeName(attributeName),
sizeInBytes(sizeInBytes) {}
void reallyLongMethodNameWithLotsOfArguments(bool argument1,
int someSecondArgument, int bestArgument) {
std::pair<bool, int> pair = {
argument1,
argument2,
};
// etc
}
int sizeInBytes;
private:
int mAttributeName;
static int sGlobalAttribute;
static constexpr int FOO_COUNT = 10;
enum {
ONE, TWO, THREE
};
};
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
.cpp fileSTL limited in filament public headers to:
arrayinitializer_listiteratorlimitsoptionaltype_traitsutilityvariantFor libfilament the rule of thumb is that STL headers that don't generate code are allowed (e.g. type_traits),
conversely containers and algorithms are not allowed. There are exceptions such as array. See above for the full list.
STL headers are banned entirely, from public and private headers as well as implementation files:
iostreamSorting the headers is important to help catching missing #include directives.
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Bar.cpp
#include <foo/Bar.h>
#include "PrivateStuff.h"
#include <foo/Alloc.h>
#include <foo/Bar.h>
#include <utils/compiler.h>
#include <algorithm>
#include <iostream>
#include <assert.h>
#include <string.h>
std::string in the Filament core renderer. Prefer utils::CString or std::string_view.std::string in tools, always include the std:: qualifier to disambiguate it
from other string types.auto only when the type appears on the same line or with iterators and lambdas.auto foo = new Foo();
for (auto& i : collection) { }