diff options
author | Nico Weber <thakis@chromium.org> | 2014-09-23 13:21:59 -0700 |
---|---|---|
committer | Nico Weber <thakis@chromium.org> | 2014-09-23 20:22:35 +0000 |
commit | 019d40fa03d9135e7db9d04c2c132af5a05e3dc2 (patch) | |
tree | eaae8f198c907a40b0759f2142a77b6d5c6168af /styleguide | |
parent | 2903f33784712aa48e18006a6bca60dd284afd97 (diff) | |
download | chromium_src-019d40fa03d9135e7db9d04c2c132af5a05e3dc2.zip chromium_src-019d40fa03d9135e7db9d04c2c132af5a05e3dc2.tar.gz chromium_src-019d40fa03d9135e7db9d04c2c132af5a05e3dc2.tar.bz2 |
Add a document describing which C++11 features we allow.
For now, this allows only a very limited set. Also describes the process we're
going to follow to allow more features. The idea is that we're gradually going
to allow more features over time.
Also included is the source of a tiny appengine app running at
chromium-cpp.appspot.com that will show the contents of the document in this
CL once it's submitted.
BUG=360096
NOTRY=true
R=ben@chromium.org, inferno@chromium.org, jamesr@chromium.org
Review URL: https://codereview.chromium.org/589413003
Cr-Commit-Position: refs/heads/master@{#296214}
Diffstat (limited to 'styleguide')
-rw-r--r-- | styleguide/c++/OWNERS | 3 | ||||
-rw-r--r-- | styleguide/c++/c++11.css | 742 | ||||
-rw-r--r-- | styleguide/c++/c++11.html | 963 | ||||
-rw-r--r-- | styleguide/c++/chromium-cpp/app.yaml | 17 | ||||
-rw-r--r-- | styleguide/c++/chromium-cpp/favicon.ico | bin | 0 -> 8348 bytes | |||
-rw-r--r-- | styleguide/c++/chromium-cpp/index.yaml | 12 | ||||
-rwxr-xr-x | styleguide/c++/chromium-cpp/main.py | 49 |
7 files changed, 1786 insertions, 0 deletions
diff --git a/styleguide/c++/OWNERS b/styleguide/c++/OWNERS new file mode 100644 index 0000000..2157101 --- /dev/null +++ b/styleguide/c++/OWNERS @@ -0,0 +1,3 @@ +ajwong@chromium.org +jamesr@chromium.org +thakis@chromium.org diff --git a/styleguide/c++/c++11.css b/styleguide/c++/c++11.css new file mode 100644 index 0000000..e781b1c --- /dev/null +++ b/styleguide/c++/c++11.css @@ -0,0 +1,742 @@ +/* + * Copyright 2014 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +html { + margin:0; + padding:0; + border:0; +} + +.bp-reset-element, +body, +h1, +h2, +h3, +h4, +h5, +h6, +article, +aside, +details, +figcaption, +figure, +footer, +header, +hgroup, +menu, +nav, +section, +summary, +blockquote, +q, +th, +td, +caption, +table, +div, +span, +object, +iframe, +p, +pre, +a, +abbr, +acronym, +address, +code, +del, +dfn, +em, +img, +dl, +dt, +dd, +ol, +ul, +li, +fieldset, +form, +label, +legend, +caption, +tbody, +tfoot, +thead, +tr { + margin:0; + padding:0; + border:0; + font-weight:inherit; + font-style:inherit; + font-size:100%; + font-family:inherit; + vertical-align:baseline; +} + +body { + font-family:'Arial', sans-serif; + font-size:81.25%; + color:#222; + background-color:#fff; + line-height:1.67; + overflow: auto; + margin-right: 100px; + margin-left: 100px; + margin-top: 50px; + margin-bottom: 80px; +} + +p { + width:600px; +} + +h1, +h2, +p.h2, +h3, +h4, +h5, +h6 { + font-weight:bold; +} + +h1 { + margin-bottom:.50em; +} + +h2, +p.h2, +h3, +h4, +h5, +h6 { + margin-top:1.5em; + margin-bottom:.75em; +} + +h1,header {font-size:192%;} +#gc-content h1 {font-size:2em;} +h2, p.h2 {font-size:167%;} +h3 {font-size:145%;} +h4 {font-size:130%;} +h5 {font-size:110%;} + +p { + margin:0 0 1.5em; +} + +p .left { + display:inline; + float:left; + margin:1.5em 1.5em 1.5em 0; + padding:0; +} + +p .right { + display:inline; + float:right; + margin:1.5em 0 1.5em 1.5em; + padding:0; +} + +article, +aside, +details, +figcaption, +figure, +footer, +header, +hgroup, +menu, +nav, +section, +summary { + display:block; +} + +blockquote, +q { + quotes:'' ''; +} +blockquote:before, +blockquote:after, +q:before, +q:after { + content:''; +} + +blockquote { + margin:1.5em; +} + +blockquote#nav { + margin-top:0; +} + +section { + margin-bottom:1.5em; +} + +a[href=''] { + cursor:default; +} + +strong, +dfn { + font-weight:bold; +} + +em, +dfn { + font-style:italic; +} + +sup, +sub { + line-height:0; +} + +abbr, +acronym { + border-bottom:1px dotted #666; +} + +address { + margin:0 0 1.5em; + font-style:italic; +} + +del { + color:#666; +} + +pre { + margin:1.5em 0; + white-space:pre; +} + +pre, +code, +kbd, +tt { + font:1em 'Droid Sans Mono', monospace; + line-height:1.5; +} + +dl { + margin:0 0 1.5em 0; +} + +dl dt { + font-weight:bold; +} + +dd { + margin-left:1.5em; +} + +hr { + height:0; + border:0; + border-top:1px solid #ccc; + background-color:#ccc; +} + +table { + border:1px solid #bbb; + border-spacing:0; + border-collapse:collapse; + margin:0 0 1.5em; + vertical-align:middle; + width:100%; +} + +table.unlined, +table.unlined th, +table.unlined tr, +table.unlined td { + border:0; +} + +th, +td, +caption { + float:none !important; + text-align:left; + font-weight:normal; + vertical-align:middle; + padding:4px; +} + +caption { + padding:0; +} + +td { + border:1px solid #bbb; + vertical-align:top; +} + +th { + border:0; + border-bottom:1px solid black; + font-weight:bold; + background:rgb(229, 236, 249); +} + +th:only-of-type { + border-bottom:1px solid rgb(244, 244, 244); + background-color: rgb(238, 238, 238); + vertical-align: top; +} + +table th code { + background-color:inherit; + color:inherit; +} + +table tfoot th { + border:1px solid #bbb; +} + +tfoot { + font-style:italic; +} + +caption { + background:#eee; +} + +table[border='0'] { + border:none; +} + +table[border='0']>tbody>tr>td, +table[border='0']>tr>td { + border:none; +} + +tr.alt td, +td.alt { + background-color:#efefef; +} + +table.striped tr:nth-child(even) td, +table tr.even td { + background:#efefef; +} + +table.columns { + border:none; +} + +table.columns>tbody>tr>td, +table.columns>tr>td { + border:none; + padding:0 3em 0 0; +} + +table.columns>tbody>tr>td:last-child, +table.columns>tr>td:last-child { + border:none; + padding:0; +} + +.two-columns td { + width: 50%; + vertical-align:top; +} + +ul, +ol { + margin:0 1.5em 1.5em 0; + padding-left:2em; +} + +li ul, +li ol { + margin:0; +} + +ul { + list-style-type:disc; +} + +ol { + list-style-type:decimal; +} + +ul { + list-style-type:disc; +} + +ul ul { + list-style-type:circle; +} + +ul ul ul { + list-style-type:square; +} + +ul.disc { + list-style-type:disc; +} + +ul.circle { + list-style-type:circle; +} + +ul.square { + list-style-type:square; +} + +ol { + list-style-type:decimal; +} + +ol ol { + list-style-type:lower-alpha; +} + +ol ol ol { + list-style-type:lower-roman; +} + +ol ul { + list-style-type:circle; +} + +ol.decimal { + list-style-type:decimal; +} + +ol.upper-alpha { + list-style-type:upper-alpha; +} + +ol.lower-alpha { + list-style-type:lower-alpha; +} + +ol.upper-roman { + list-style-type:upper-roman; +} + +ol.lower-roman { + list-style-type:lower-roman; +} + +ol.nolist, +ul.nolist { + padding-left:0; + list-style-image:none; + list-style-type:none; + margin-left:0; +} + +li p { + margin-bottom:0.75em; +} + +figure { + margin:0 0 1.5em; + text-align:center; +} + +figure.right { + float:right; + margin:5px 1em 1em; +} + +figcaption { + font-style:italic; + font-size:90%; + text-align:center; +} + +.center { + text-align:center; +} + +.clear, .clearboth { + clear:both; +} + +.class-done { + padding-top:2em; +} + +a.file { + font-family:monospace; + font-size:120%; +} + +.navtop { + font-size: xx-small; + float:right; +} + +.loud { + font-weight:bold; +} + +.quiet { + color:#999; + stress:30; +} + +.light-title { + font-size:150%; + border:0; + color:#666; +} + +code, +kbd, +pre { + color:#009900; +} + +code { + white-space: nowrap; +} + +pre > code { + white-space: inherit; +} + +kbd { + font-weight: bold; +} + +table.striped code { + background-color:inherit; +} + +pre { + padding:6px 10px; + background-color:#FAFAFA; + border:1px solid #bbb; + overflow:auto; +} + +pre.prettyprint { + padding:6px 10px !important; + border:1px solid #bbb !important; +} + +code.bad, code.badcode { + color: magenta; +} + +pre.bad, pre.badcode { + background-color:#ffe6d8; + border-top:1px inset #a03; + border-left:1px inset #a03; +} + +.codesample { + border-top:1px inset silver; + border-left:1px inset silver; + display:inline-block; + margin-bottom:10px; +} + +.codesample pre { + margin-bottom:0; +} + +.codesample.good { + border-top:1px inset green; + border-left:1px inset green; + vertical-align: top; +} + +.codesample.bad { + border-top:1px inset #a03; + border-left:1px inset #a03; + vertical-align: top; +} + +.codesample > p { + margin-bottom: 0; + font-weight: bold; + border: 1px solid #888; + border-bottom: 0; + padding: 0 .25em; +} + +.codesample.bad > p { + background-color: #ffeaea; +} + +.codesample.bad > p:before { + content: "BAD: "; +} + +.codesample.good > p { + background-color: #eaffea; +} + +.codesample.good > p:before { + content: "GOOD: "; +} + +.codesample.bad > pre { + background-color: #ffe6d8; +} + +.codesample > pre { + margin-top: 0; +} + +.border { + border:1px solid #aaa; + padding:3px; +} + +.expandable { + display:block; + margin-left:16px; + min-height:20px; +} + +.expandable .exw-control { + position:absolute; + margin-top:-6px; + margin-left:-16px; + cursor:pointer; + display:block; + text-decoration:none; + color:#222; + font-size:20px; +} + +.hide { + display:none !important; +} + +.show { + display:block !important; +} + +.hidden { + display:none; +} + +.invisible { + width:0 !important; + height:0 !important; + border:0 !important; +} + +.announcement { + background-color:#FFECBC; + border-radius:2px; + border:1px solid #ffbf68; + padding:10px 20px; + color:#666; + margin-top:10px; + margin-right:16px; +} + +.announcement>div strong { + font-size:1.2em; +} + +.announcement>div#gc-description a { + text-decoration:underline; +} + +.quiet { + color:#919191; +} + +.quieter { + color:#ccc; +} + +.doublespace, +.doublespace li { + margin-top:1em; + line-height:200%; +} + +.yellow { + background-color:#fffbd9; + border-left-color:#ffef70; +} + +.orange { + background-color:#FFECBC; + border-left-color:#ffef70; +} + +.red { + background-color:#ffe6d8; + border-left-color:#a03; +} + + +aside.caution, +aside.lapswarning, +aside.note, +aside.special, +aside.tip, +aside.warning { + margin-bottom:1.5em; +} + +.note, +.caution, +.tip, +.warning, +.special { + background-color:#efefef; + padding:6px 8px 6px 10px; + border-left:6px solid #999; +} + +.note>h4, +.caution>h4, +.tip>h4, +.warning>h4, +.special>h4, +.sidebar>h4, +.special-sidebox>h4{ + font-weight:bold; + font-size:1em; + margin:0.125em; +} + +.note>p:last-child, +.caution>p:last-child, +.special>p:last-child, +.tip>p:last-child, +.warning>p:last-child { + margin:0; +} + +.caution, +.tip { + background-color:#fffbd9; + border-left-color:#ffef70; +} + +.warning { + background-color:#ffe6d8; + border-left-color:#a03; +} + +.note, +.special { + background-color:#e5ecf9; + border-left-color:#36c; +} + +.attention { + color:#990000; + font-weight:bold; +} diff --git a/styleguide/c++/c++11.html b/styleguide/c++/c++11.html new file mode 100644 index 0000000..8370774 --- /dev/null +++ b/styleguide/c++/c++11.html @@ -0,0 +1,963 @@ +<!DOCTYPE html> +<!-- +Copyright 2014 The Chromium Authors. All rights reserved. +Use of this source code is governed by a BSD-style license that can be +found in the LICENSE file. +--> +<html> +<head> +<meta charset="utf-8"> +<link rel="stylesheet" href="c++11.css"> +<style> +table tbody tr td:first-child { + font-weight: bold; + font-size: 110%; +} +</style> +</head> +<body> +<div id="content"> +<h1>C++11 use in Chromium</h1> + +<p><i>This document lives at src/styleguide/c++/c++11.html in a Chromium +checkout.</i></p> + +<p>This document summarizes the features of C++11 (both in the language itself +and in enhancements to the Standard Library) and describes which features are +allowed in Chromium and contains pointers to more detailed information. The +Guide applies to Chromium and its subprojects. Subprojects can choose to be +more restrictive if they need to compile on more toolchains than Chromium.</p> + +<p>You can propose to make a feature available or to ban a +feature by sending an email to chromium-dev. Ideally include a short blurb +on what the feature is, and why you think it should or should not be allowed. +Ideally, the list will arrive at some consensus and the wiki page will be +updated to mention that consensus. If there's no consensus, +<code>src/styleguide/C++/OWNERS</code> get to decide -- for divisive features, we expect +the decision to be to not use the feature yet and possibly discuss it again a +few months later, when we have more experience with the language.</p> + +<p class="warning">Unless otherwise noted, <strong>no</strong> C++11 +<strong>library</strong> features are allowed.</p> + +<h2 id="whitelist">C++11 Allowed Features</h2> + +<p>The following features are currently allowed.</p> + +<table id="whitelist_lang_list" class="unlined striped"> +<tbody> + +<tr> +<th style='width:220px;'>Feature</th> +<th style='width:260px;'>Snippet</th> +<th style='width:240px;'>Description</th> +<th style='width:240px;'>Documentation Link</th> +<th style='width:240px;'>Notes and Discussion Thread</th> +</tr> + +<tr> +<td>Angle Bracket Parsing in Templates</td> +<td><code>>></code> for <code>> ></code> and <br /> +<code><::</code> for <code>< ::</code></td> +<td>More intuitive parsing of template parameters</td> +<td><a href="http://stackoverflow.com/questions/15785496/c-templates-angle-brackets-pitfall-what-is-the-c11-fix"> +C++ Templates Angle Brackets Pitfall</a></td> +<td>Recommended to increase readability. Approved without discussion.</td> +</tr> + +<tr> +<td>Local Types as Template Arguments</td> +<td></td> +<td>Allows local and unnamed types as template arguments</td> +<td><a href="http://stackoverflow.com/questions/742607/using-local-classes-with-stl-algorithms"> +Local types, types without linkage and unnamed types as template arguments</a></td> +<td>Usage should be rare. Approved without discussion.</td> +</tr> + +<tr> +<td>Standard Integers</td> +<td>Typedefs within <code><stdint.h></code> +and <code><inttypes></code></td> +<td>Provides fixed-size integers independent of platforms</td> +<td><a href="http://www.cplusplus.com/reference/cstdint/"> +<stdint.h> (cstdint)</a></td> +<td>Already in common use in the codebase. Approved without discussion.</td> +</tr> + +</tbody> +</table> + +<h2 id="blacklist">C++11 Blacklist (Disallowed and Banned Features)</h2> + +<p>This section lists features that are not allowed to be used yet. + +<h3 id="blacklist_banned">C++11 Banned Features</h3> + +<p>None yet! This section will list C++11 features that are not allowed in the +Chromium codebase. +</p> + +<!-- +<table id="banned_list" class="unlined striped"> +<tbody> + +<tr> +<th style='width:240px;'>Feature or Library</th> +<th style='width:240px;'>Snippet</th> +<th style='width:240px;'>Description</th> +<th style='width:240px;'>Documentation Link</th> +<th style='width:240px;'>Status</th> +</tr> + +</tbody> +</table> +--> + +<h3 id="blacklist_review">C++11 Features To Be Discussed</h3> + +<p>The following C++ language features are currently disallowed. +See the top of this page on how to propose moving a feature from this list +into the allowed or banned sections. Note that not all of these features +work in all our compilers yet.</p> + +<table id="blacklist_review_list" class="unlined striped"> +<tbody> + +<tr> +<th style='width:240px;'>Feature</th> +<th style='width:240px;'>Snippet</th> +<th style='width:240px;'>Description</th> +<th style='width:240px;'>Documentation Link</th> +<th style='width:240px;'>Notes</th> +</tr> + +<tr> +<td>Aliases</td> +<td><code>using <i>new_alias</i> = <i>typename</i></code></td> +<td>Allow parameterized typedefs</td> +<td><a href="http://en.cppreference.com/w/cpp/language/type_alias">Type alias (using syntax)</a></td> +<td></td> +</tr> + +<tr> +<td>Alignment Features</td> +<td> +<code>alignas</code> specifier, +<code>std::alignment_of<T></code>, +<code>std::aligned_union<Size, ...Types></code> and +<code>std::max_align_t</code></td> +<td>Object alignment</td> +<td><a href="http://en.cppreference.com/w/cpp/types/alignment_of">std::alignment_of</a></td> +<td></td> +</tr> + +<tr> +<td>Attributes</td> +<td><code>[[<i>attribute_name</i>]]</code></td> +<td>Attaches properties to declarations that +specific compiler implementations may use.</td> +<td><a href="http://www.codesynthesis.com/~boris/blog/2012/04/18/cxx11-generalized-attributes/"> +C++11 generalized attributes</a></td> +<td></td> +</tr> + +<tr> +<td>Automatic Types</td> +<td><code>auto</code></td> +<td>Automatic type deduction</td> +<td><a href="http://go/totw:4"> +Tip of the Week #4: Use <code>const auto&</code> and +<code>auto</code> to replace complex declarations</a></td> +<td><a +href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#auto">Google +Style Guide on <code>auto</code></a></td> +</tr> + +<tr> +<td>Constant Expressions</td> +<td><code>constexpr</code></td> +<td>Compile-time constant expressions</td> +<td><a href="http://go/totw:57"> +Tip of the Week #57: <code>constexpr</code> is forever</a></td> +<td>Not supported in MSVS2013. <a +href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#constexpr">Google +Style Guide on <code>constexpr</code></a></td> +</tr> + +<tr> +<td>Declared Type Accessor</td> +<td><code>decltype(<i>expression</i>)</code></td> +<td>Provides a means to determine the type of an expression at compile-time, +useful most often in templates.</td> +<td><a href="http://en.cppreference.com/w/cpp/language/decltype"> +decltype specifier</a></td> +<td></td> +</tr> + +<tr> +<td>Default Function Creation</td> +<td><code><i>Function</i>(<i>arguments</i>) = default;</code></td> +<td>Instructs the compiler to generate a default version +of the indicated function</td> +<td><a href="http://stackoverflow.com/questions/823935/whats-the-point-in-defaulting-functions-in-c11"> +What's the point in defaulting functions in C++11?</a></td> +<td></td> +</tr> + +<tr> +<td>Default Function Template Arguments</td> +<td><code>template <typename T = <i>type</i>> <br /> + <i>type</i> <i>Function</i>(T <i>var</i>) {}</code></td> +<td>Allow function templates, like classes, to have default arguments</td> +<td><a href="http://stackoverflow.com/questions/2447458/default-template-arguments-for-function-templates"> +Default Template Arguments for Function Templates</a></td> +<td></td> +</tr> + +<tr> +<td>Delegated Constructors</td> +<td><code>Class() : Class(0) {}</code><br /> +<code>Class(<i>type</i> <i>var</i>) : Class(<i>var</i>, 0)</code></td> +<td>Allow overloaded constructors to use common initialization code</td> +<td><a href="https://www.ibm.com/developerworks/community/blogs/5894415f-be62-4bc0-81c5-3956e82276f3/entry/introduction_to_the_c_11_feature_delegating_constructors?lang=en"> +Introduction to the C++11 feature: delegating constructors</a></td> +<td></td> +</tr> + +<tr> +<td>Enumerated Type Classes</td> +<td><code>enum class <i>classname</i></code></td> +<td>Provide enums as full classes, with no implicit +conversion to booleans or integers</td> +<td><a href="http://stackoverflow.com/questions/6936030/do-we-really-need-enum-class-in-c11"> +enum-class</a></td> +<td></td> +</tr> + +<tr> +<td>Exception Features</td> +<td><code>noexcept</code>, <code>exception_ptr</code>, +<code>current_exception()</code>, <code>rethrow_exception</code>, +and <code>nested_exception</code></td> +<td>Enhancements to exception throwing and handling</td> +<td><a href="http://en.cppreference.com/w/cpp/error/exception"> +std::exception</a></td> +<td>Exceptions are banned by the +<a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Exceptions"> +C++ Style Guide</a>.</td> +</tr> + +<tr> +<td>Explicit Conversion Operators</td> +<td><code>explicit operator <i>type</i>() { +<br /> // code<br /> }</code></td> +<td>Allows conversion operators that cannot be implicitly invoked</td> +<td><a href="http://en.cppreference.com/w/cpp/language/explicit"> +explicit specifier</a></td> +<td></td> +</tr> + +<tr> +<td>Final Declarations</td> +<td><code>final</code></td> +<td>Indicates that a class or function is final and cannot be overridden</td> +<td><a href="http://go/totw:54"> +Tip of the Week #54: Controlling Your Inheritance</a></td> +<td><code>FINAL</code> is already widely used in the codebase.</td> +</tr> + +<tr> +<td>Function Local Variable</td> +<td><code>__func__</code></td> +<td>Provides a local variable of the name of the enclosing +function for logging purposes</td> +<td><a href="http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=338"> +The __func__ Predeclared Identifier is Coming to C++</a></td> +<td></td> +</tr> + +<tr> +<td>Function Suppression</td> +<td><code><i>Function</i>(<i>arguments</i>) = delete;</code></td> +<td>Suppresses the implementation of a function, especially a +synthetic function such as a copy constructor</td> +<td>TODO: documentation link</td> +<td></td> +</tr> + +<tr> +<td>(Uniform) Initialization Syntax</td> +<td><code><i>type</i> <i>name</i> { [<i>value</i> ..., <i>value</i>]};</code></td> +<td>Allows any object of primitive, aggregate or class +type to be initialized using brace syntax</td> +<td><a href="http://go/totw:58"> +Tip of the Week #58: Initializer Lists and the Uniform Initialization Syntax</a></td> +<td></td> +</tr> + +<tr> +<td>Inline Namespaces</td> +<td><code>inline</code></td> +<td>Allows better versioning of namespaces</td> +<td><a href="http://en.cppreference.com/w/cpp/language/namespace">Namespaces</a></td> +<td>Under investigation, unclear how it will work with +components</td> +</tr> + +<tr> +<td>Lambda Expressions</td> +<td><code>[<i>captures</i>](<i>params</i>) -> <i>ret</i> { <i>body</i> }</code></td> +<td>Anonymous functions</td> +<td><a href="http://en.cppreference.com/w/cpp/language/lambda">Lambda functions</a></td> +<td>No default captures (<a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Lambda_expressions">Google Style Guide</a>).</td> +</tr> + +<tr> +<td><code>long long</code> Type</td> +<td><code>long long <i>var</i>= <i>value</i>;</code></td> +<td>An integer of at least 64 bits</td> +<td><a href="http://en.cppreference.com/w/cpp/language/types"> +Fundamental types</a></td> +<td></td> +</tr> + +<tr> +<td>Non-Static Class Member Initializers</td> +<td> +<code> +class C {<br /> + <i>type</i> <i>var</i> = <i>value</i>;<br/> + C() // copy-initializes <i>var</i><br/> +</code> +<td>Allows non-static class members to be initialized at their definitions (outside constructors)</td> +<td><a href="http://go/totw:61"> +Tip of the Week #58: Non-Static Class Member Initializers</a> and +<a href="http://en.cppreference.com/w/cpp/language/data_members"> +Non-static data members</a></td> +<td></td> +</tr> + +<tr> +<td>Null Pointer Constant</td> +<td><code>nullptr</code></td> +<td>Declares a type-safe null pointer</td> +<td><a href="http://go/totw:39"> +Tip of the Week #39: Prefer C++11’s nullptr to NULL or 0</a></td> +<td><a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#0_and_nullptr/NULL">Google Style Guidwe</a>. +</td> +</tr> + +<tr> +<td>Overrides</td> +<td><code>override</code></td> +<td>Indicates that a class or function overrides a base implementation</td> +<td><a href="http://go/totw:54"> +Tip of the Week #54: Controlling Your Inheritance</a></td> +<td><code>OVERRIDE</code> is already widely used in the codebase.</td> +</tr> + +<tr> +<td>Range-Based For Loops</td> +<td><code>for (<i>type</i> <i>var</i> : <i>range</i>)</code></td> +<td>Facilitates a more concise syntax for iterating over the elements +of a container (or a range of iterators) in a <code>for</code> loop</td> +<td>TODO: documentation link/a></td> +<td></td> +</tr> + +<tr> +<td>Raw String Literals</td> +<td><code>string <i>var</i>=R"(<i>raw_string</i>)";</code></td> +<td>Allows a string to be encoded without any escape +sequences, easing parsing in regex expressions, for example</td> +<td>TODO: documentation linkRaw String Literals</a></td> +<td></td> +</tr> + +<tr> +<td>Rvalue References (and Move Semantics)</td> +<td><code>T(T&& t)</code> and <code>T& operator=(T&& t)</code></td> +<td>Reference that only binds to a temporary object</td> +<td>TODO: documentation linkstruction and assignment</a></td> +<td></td> +</tr> + +<tr> +<td>Static Assertions</td> +<td><code>static_assert(<i>bool</i>, <i>string</i>)</code></td> +<td>Tests compile-time conditions</td> +<td><<a href="http://en.cppreference.com/w/cpp/language/static_assert">Static Assertion</a></td> +<td></td> +</tr> + +<tr> +<td>Union Class Members</td> +<td><code>union <i>name</i> { <i>class</i> <i>var</i>}</code></td> +<td>Allows class type members</td> +<td><a href="http://en.cppreference.com/w/cpp/language/union"> +Union declarations</a></td> +<td></td> +</tr> + +<tr> +<td>User-Defined Literals</td> +<td><code><i>type</i> <i>var</i> = <i>literal_value</i>_<i>type</i></code></td> +<td>Allows user-defined literal expressions</td> +<td>TODO: documentation link</td> +<td></td> +</tr> + +<tr> +<td>UTF-8 String Literals</td> +<td><code>u8"<i>string</i>"</code></td> +<td>Enforces UTF-8 encoding on all string literals</td> +<td><a href="http://en.cppreference.com/w/cpp/language/string_literal"> +string literal</a></td> +<td></td> +</tr> + +<tr> +<td>UTF-16 and UTF-32 Support (16-Bit and 32-Bit Character Types)</td> +<td><code>char16_t</code> and <code>char32_t</code></td> +<td>Provides character types for handling 16-bit +and 32-bit code units (useful for encoding +UTF-16 and UTF-32 string data)</td> +<td><a href="http://en.cppreference.com/w/cpp/language/types"> +Fundamental types</a></td> +<td>Non-UTF-8 text is banned by the +<a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Non-ASCII_Characters"> +C++ Style Guide</a>. However, may be useful for +consuming non-ASCII data.</td> +</tr> + + +<tr> +<td>Variadic Macros</td> +<td><code>#define <i>MACRO</i>(...) <i>Impl</i>(<i>args</i>, __VA_ARGS__)</code></td> +<td>Allows macros that accept a variable number of arguments</td> +<td><a href="http://stackoverflow.com/questions/4786649/are-variadic-macros-nonstandard"> +Are Variadic macros nonstandard?</a></td> +<td></td> +</tr> + +<tr> +<td>Variadic Templates</td> +<td><code>template <<i>typename</i> ... <i>arg</i>></code></td> +<td>Allows templates that accept a variable number of arguments</td> +<td>TODO: documentation link</td> +<td></td> +</tr> + +</tbody> +</table> + +<h3 id="blacklist_stdlib">C++11 Standard Library features</h3> + +<details> + +<p><summary class="note">All C++11 <strong>Standard Library features are currently +banned</strong>, because they are not supported on all of our toolchains yet. +In particular, chromium/android is currently using STLport, and chromium/mac is +currently using libstdc++4.2, which predate C++11. +</summary></p> + +<table id="banned_stdlib" class="unlined striped"> + +<tbody> +<tr> +<th style='width:240px;'>Feature</th> +<th style='width:240px;'>Snippet</th> +<th style='width:240px;'>Description</th> +<th style='width:240px;'>Documentation Link</th> +<th style='width:240px;'>Style Guide Usage</th> +</tr> + +<tr> +<td>Address Retrieval</td> +<td><code>std::addressof()</code></td> +<td>Obtains the address of an object even with overloaded <code>operator&</code></td> +<td><a href="http://en.cppreference.com/w/cpp/memory/addressof">std::addressof</a></td> +<td>Usage should be rare as +<a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Operator_Overloading"> +Operator Overloading</a> is rare and <code>&s;</code> +should suffice in most cases. May be preferable +over <code>&s;</code> for performing object +identity checks.</td> +</tr> + +<tr> +<td>Aligned Storage</td> +<td><code>std::aligned_storage<Size, Align>::type</code></td> +<td>Declare uninitialized storage having a specified alignment.</td> +<td><a href="http://en.cppreference.com/w/cpp/types/aligned_storage">std::aligned_storage</a></td> +<td>Note: <code>std::aligned_storage</code> is allowed, but some other C++11 +alignment features are still disallowed.</td> +</tr> + +<tr> +<td>Allocator Traits</td> +<td><code>std::allocator_traits</code></td> +<td>Provides an interface for accessing custom allocators</td> +<td><a href="http://en.cppreference.com/w/cpp/memory/allocator_traits"> +std::allocator_traits</a></td> +<td>Usage should be rare.</td> +</tr> + +<tr> +<td>Atomics</td> +<td><code>std::atomic</code> and others in <code><atomic></code></td> +<td>Fine-grained atomic types and operations</td> +<td><a href="http://en.cppreference.com/w/cpp/atomic"><atomic></a></td> +<td></td> +</tr> + +<tr> +<td>Arrays</td> +<td><code>std::array</code></td> +<td>A fixed-size replacement for built-in arrays, with STL support</td> +<td><a href="http://en.cppreference.com/w/cpp/container/array"> +std::array</a></td> +<td></td> +</tr> + +<tr> +<td>Begin and End Non-Member Functions</td> +<td><code>std::begin()</code> and <code>std::end()</code></td> +<td>Allows use of free functions on any container, including +built-in arrays</td> +<td><a href="http://en.cppreference.com/w/cpp/iterator/begin"> +std::begin</a> and +<a href="http://en.cppreference.com/w/cpp/iterator/end"> +std::end</a></td> +<td>Useful for built-in arrays.</td> +</tr> + +<tr> +<td>Bind Operations</td> +<td><code>std::bind(<i>function</i>, <i>args</i>, ...)</code></td> +<td>Declares a function object bound to certain arguments</td> +<td>TODO: documentation link</td> +<td></td> +</tr> + +<tr> +<td>C Floating-Point Environment</td> +<td><code><cfenv></code></td> +<td>Provides floating point status flags and control modes for C-compatible code</td> +<td><a href="http://en.cppreference.com/w/cpp/header/cfenv">Standard library header <cfenv></a></td> +<td>Compilers do not support use</td> +</tr> + +<tr> +<td>Chrono Library</td> +<td><code><chrono></code></td> +<td>Provides a standard date and time library</td> +<td><a href="http://en.cppreference.com/w/cpp/chrono">Date and time utilities</a></td> +<td></td> +</tr> + +<tr> +<td>Complex Inverse Trigonometric and Hyperbolic Functions</td> +<td>Functions within <code><complex></code></td> +<td>Adds inverse trigonomentric and hyperbolic non-member functions to +the <code><complex></code> library.</td> +<td><a href="http://en.cppreference.com/w/cpp/numeric/complex">std::complex</a></td> +<td></td> +</tr> + +<tr> +<td>Conditional Type Selection</td> +<td><code>std::enable_if</code> and <code>std::conditional</code></td> +<td>Enables compile-time conditional type selection</td> +<td><a href="http://en.cppreference.com/w/cpp/types/enable_if"> +std::enable_if</a> and +<a href="http://en.cppreference.com/w/cpp/types/conditional"> +conditional</a></td> +<td></td> +</tr> + +<tr> +<td>Constant Iterator Methods on Containers</td> +<td><code>std::cbegin()</code> and <code>std::cend()</code></td> +<td>Enforces iteration methods that don't change container contents</td> +<td>TODO: documentation link</td> +<td></td> +</tr> + +<tr> +<td>Construct Elements in Containers</td> +<td><code>emplace()</code>,<code>emplace_back()</code>, +<code>emplace_front()</code>, <code>emplace_hint()</code></td> +<td>Constructs elements directly within a container without a copy +or a move</td> +<td>TODO: documentation link</td> +<td>Use where element construction within a container +is needed.</td> +</tr> + +<tr> +<td>Container Compaction Functions</td> +<td><code>std::vector::shrink_to_fit()</code>, +<code>std::deque::shrink_to_fit()</code>, and +<code>std::string::shrink_to_fit()</code></td> +<td>Requests the removal of unused space +in the container</td> +<td><a href="http://en.cppreference.com/w/cpp/container/vector/shrink_to_fit"> +std::vector::shrink_to_fit</a>, +<a href="http://en.cppreference.com/w/cpp/container/deque/shrink_to_fit"> +std::deque::shrink_to_fit</a>, and +<a href="http://en.cppreference.com/w/cpp/string/basic_string/shrink_to_fit"> +std::basic_string::shrink_to_fit</a></td> +<td></td> +</tr> + +<tr> +<td>Date/Time String Formatting Specifiers</td> +<td><code>std::strftime()</code></td> +<td>Converts date and time information into a +formatted string using new specifiers</td> +<td><a href="http://en.cppreference.com/w/cpp/chrono/c/strftime"> +std::strftime</a></td> +<td></td> +</tr> + +<tr> +<td>Function Return Type Deduction</td> +<td><code>std::result_of<<i>Functor(ArgTypes...)</i>></code></td> +<td>Extracts the return type from the type signature of +a function call invocation at compile-time.</td> +<td><a href="http://en.cppreference.com/w/cpp/types/result_of"> +std::result_of</a></td> +<td> +<a href="http://stackoverflow.com/questions/15486951/why-does-stdresult-of-take-an-unrelated-function-type-as-a-type-argument"> +Why does std::result_of take an (unrelated) function type as a type argument? +</a></td> +</tr> + +<tr> +<td>Function Objects</td> +<td><code>std::function</code></td> +<td>Wraps a standard polymorphic function</td> +<td>TODO: documentation link</td> +<td></td> +</tr> + +<tr> +<td>Forward Lists</td> +<td><code>std::forward_list</code></td> +<td>Provides an efficient singly linked list</td> +<td><a href="http://en.cppreference.com/w/cpp/container/forward_list"> +std::forward_list</a></td> +<td></td> +</tr> + +<tr> +<td>Gamma Natural Log</td> +<td><code>std::lgamma()</code></td> +<td>Computes the natural log of the gamma of a +floating point value</td> +<td><a href="http://en.cppreference.com/w/cpp/numeric/math/lgamma"> +std::lgamma</a></td> +<td></td> +</tr> + +<tr> +<td>Garbage Collection Features</td> +<td><code>std::{un}declare_reachable()</code> and +<code>std::{un}declare_no_pointers()</code></td> +<td>Enables garbage collection implementations</td> +<td><a href="http://en.cppreference.com/w/cpp/memory/gc/declare_reachable"> +std::declare_reachable</a> +and <a href="http://en.cppreference.com/w/cpp/memory/gc/declare_no_pointers"> +std::declare_no_pointers</a></td> +<td></td> +</tr> + +<tr> +<td>Heap Validation</td> +<td><code>std::is_heap()</code></td> +<td>Checks whether an iterator range is in fact a heap</td> +<td>TODO: documentation link</td> +<td></td> +</tr> + +<tr> +<td>Is Nan</td> +<td><code>std::isnan()</code></td> +<td>Determines if a floating point value is not-a-number</td> +<td><a href="http://en.cppreference.com/w/cpp/numeric/math/isnan">std::isnan</a></td> +<td></td> +</tr> + +<tr> +<td>Iterator Operators</td> +<td><code>std::next()</code> and <code>std::prev()</code></td> +<td>Copies an iterator and increments or decrements the copy by +some value</td> +<td><a href="http://en.cppreference.com/w/cpp/iterator/next">std::next</a> +and <a href="http://en.cppreference.com/w/cpp/iterator/prev">std::prev</a> +</td> +<td></td> +</tr> + +<tr> +<td>Initializer Lists</td> +<td><code>std::initializer_list<T></code></td> +<td>Allows containers to be initialized with aggregate elements</td> +<td><a href="http://go/totw:58"> +Tip of the Week #58: Initializer Lists and the Uniform Initialization Syntax</a></td> +<td></td> +</tr> + +<tr> +<td>Move Semantics</td> +<td><code>std::move()</code></td> +<td>Facilitates efficient move operations</td> +<td><a href="http://en.cppreference.com/w/cpp/utility/move"> +<code>std::move</code> reference</a></td> +<td></td> +</tr> + +<tr> +<td>Pointer Traits Class Template</td> +<td><code>std::pointer_traits</code></td> +<td>Provides a standard way to access properties +of pointers and pointer-like types</td> +<td><a href="http://en.cppreference.com/w/cpp/memory/pointer_traits"> +std::pointer_traits</a></td> +<td>Useful for determining the element type +pointed at by a (possibly smart) pointer.</td> +</tr> + +<tr> +<td>Random Number Generators</td> +<td>Functions within <code><random></code></td> +<td>Random number generation algorithms and utilities</td> +<td><a href="http://en.cppreference.com/w/cpp/numeric/random"> +Pseudo-random number generation</a></td> +<td></td> +</tr> + +<tr> +<td>Ratio Template Class</td> +<td><code>std::ratio<<i>numerator</i>, <i>denominator</i>></code></td> +<td>Provides compile-time rational numbers</td> +<td>TODO: documentation link</td> +<td></td> +</tr> + +<tr> +<td>Reference Wrapper Classes</td> +<td><code>std::reference_wrapper</code> and +<code>std::ref()</code>, <code>std::cref()</code></td> +<td>Allows you to wrap a reference within a standard +object (and use those within containers)</td> +<td><a href="http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=217"> +Reference Wrappers</a></td> +<td></td> +</tr> + +<tr> +<td>Regex Library</td> +<td><code><regex></code></td> +<td>Provides a standard regular expressions library</td> +<td><a href="http://en.cppreference.com/w/cpp/regex">Regular expressions library</a></td> +<td></td> +</tr> + +<tr> +<td>Shared Pointers</td> +<td><code>std::shared_ptr</code></td> +<td>Allows shared ownership of a pointer through reference counts</td> +<td><a href="http://en.cppreference.com/w/cpp/memory/shared_ptr">std::shared_ptr</a></td> +<td><a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Ownership_and_Smart_Pointers"> +Ownership and Smart Pointers</a></td> +</tr> + +<tr> +<td>Soft Program Exits</td> +<td><code>std::at_quick_exit()</code> +and <code>std::quick_exit()</code></td> +<td>Allows registration of functions to be called upon exit, +allowing cleaner program exit than <code>abort()</code> or +<code>exit</code></td> +<td><a href="http://en.cppreference.com/w/cpp/utility/program/quick_exit"> +std:quick_exit</a></td> +<td></td> +</tr> + +<tr> +<td>String Direct Reference Functions</td> +<td><code>std::string::front()</code> and <code>std::string::back()</code></td> +<td>Returns a reference to the front or back of a string</td> +<td><a href="http://en.cppreference.com/w/cpp/string/basic_string/front"> +std::basic_string::front</a> and +<a href="http://en.cppreference.com/w/cpp/string/basic_string/back"> +std::basic_string::back</a></td> +<td></td> +</tr> + +<tr> +<td>String to Number Functions</td> +<td><code>std::stoi()</code>, <code>std::stol()</code>, +<code>std::stoul()</code>, <code>std::stoll</code>, <code>std::stoull()</code>, +<code>std::stof()</code>, <code>std::stod()</code>, <code>std::stold()</code>, +and <code>std::to_string()</code></td> +<td>Converts strings to numbers</td> +<td><a href="http://en.cppreference.com/w/cpp/string/basic_string/stol"> +std::stoi, std::stol, std::stoll</a>, +<a href="http://en.cppreference.com/w/cpp/string/basic_string/stoul"> +std::stoul, std::stoull</a>, and +<a href="http://en.cppreference.com/w/cpp/string/basic_string/stof"> +std::stof, std::stod, std::stold</a> </td> +<td></td> +</tr> + +<tr> +<td>STL Algorithms</td> +<td>Functions within <code><algorithm></code>.</td> +<td>Enhancements to the set of STL algorithms</td> +<td><a href="http://go/totw:21"> +Tip of the Week #21: New C++11 STL Algorithms</a>. See +the <a href="http://en.cppreference.com/w/cpp/algorithm"> +Algorithms library</a> for a complete list.</td> +<td></td> +</tr> + +<tr> +<td>System Errors</td> +<td><code><system_error></code></td> +<td>Provides a standard system error library</td> +<td><a href="http://en.cppreference.com/w/cpp/error/system_error">std::system_error</a></td> +<td></td> +</tr> + +<tr> +<td>Trailing Return Types</td> +<td><code>auto <i>function declaration</i> -> <i>return_type</i></code></td> +<td>Allows trailing function return value syntax</td> +<td><a href="http://en.cppreference.com/w/cpp/language/function"> +Declaring functions</a></td> +<td></td> +</tr> + +<tr> +<td>Thread Library</td> +<td><code><thread> support, including <future>, +<mutex>, <condition_variable></code></td> +<td>Provides a standard mulitthreading library using <code>std::thread</code> and associates</td> +<td><a href="http://en.cppreference.com/w/cpp/thread">Thread support library</a></td> +<td></td> +</tr> + +<tr> +<td>Tuples</td> +<td><code>std::tuple</code></td> +<td>A fixed-size ordered collection of values of mixed types</td> +<td>TODO: documentation link</td> +<td></td> +</tr> + +<tr> +<td>Type-Generic Math Functions</td> +<td>Functions within <code><ctgmath></code></td> +<td>Provides a means to call real or complex functions +based on the type of arguments</td> +<td><a href="http://en.cppreference.com/w/cpp/header/ctgmath"> +Standard library header <ctgmath></a></td> +<td></td> +</tr> + +<tr> +<td>Type Info Enhancements</td> +<td><code>std::type_index</code> and <code>std::type_info::hash_code()</code></td> +<td>Allows type information (most often within containers) +that can be copied, assigned, or hashed</td> +<td><a href="http://en.cppreference.com/w/cpp/types/type_index"> +std::type_index</a> and +<a href="http://en.cppreference.com/w/cpp/types/type_info/hash_code"> +std::type_info::hash_code</a></td> +<td><code>std::type_index</code> is a thin wrapper for +<code>std::type_info</code>, allowing you to use it directly +within both associative and unordered containers</td> +</tr> + +<tr> +<td>Type Traits</td> +<td>Class templates within <code><type_traits></code></td> +<td>Allows compile-time inspection of the properties of types</td> +<td><a href="http://en.cppreference.com/w/cpp/header/type_traits"> +Standard library header <type_traits></a></td> +<td></td> +</tr> + +<tr> +<td>Unique Pointers</td> +<td><code>std::unique_ptr<<i>type</i>></code></td> +<td>Defines a pointer with clear and unambiguous ownership</td> +<td>TODO: documentation link</td> +<td><a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Ownership_and_Smart_Pointers"> +Ownership and Smart Pointers</a></td> +</tr> + +<tr> +<td>Unordered Associative Containers</td> +<td><code>std::unordered_set</code>, <code>std::unordered_map</code>, +<code>std::unordered_multiset</code>, and <code>std::unordered_multimap</code></td> +<td>Allows efficient containers of key/value pairs</td> +<td><a href="http://en.cppreference.com/w/cpp/container/unordered_map">std::unordered_map</a> +and <a href="http://en.cppreference.com/w/cpp/container/unordered_set">std::unordered_set</a> +</td> +<td></td> +</tr> + +<tr> +<td>Variadic Copy Macro</td> +<td><code>va_copy(va_list <i>dest</i>, va_list <i>src</i>)</code></td> +<td>Makes a copy of the variadic function arguments</td> +<td></td> +<td></td> +</tr> + +<tr> +<td>Weak Pointers</td> +<td><code>std::weak_ptr</code></td> +<td>Allows a weak reference to a <code>std::shared_ptr</code></td> +<td><a href="http://en.cppreference.com/w/cpp/memory/weak_ptr"> +std::weak_ptr</a></td> +<td><a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Ownership_and_Smart_Pointers"> +Ownership and Smart Pointers</a></td> +</tr> + +<tr> +<td>Wide String Support</td> +<td><code>std::wstring_convert</code>, +<code>std::wbuffer_convert</code>. +<code>std::codecvt_utf8</code>, <code>std::codecvt_utf16</code>, +and <code>std::codecvt_utf8_utf16</code></td> +<td>Converts between string encodings</td> +<td><a href="http://en.cppreference.com/w/cpp/locale/wstring_convert"> +std::wstring_convert</a>, +<a href="http://en.cppreference.com/w/cpp/locale/wbuffer_convert"> +std::wbuffer_convert</a>, +<a href="http://en.cppreference.com/w/cpp/locale/codecvt_utf8"> +std::codecvt_utf8</a>, +<a href="http://en.cppreference.com/w/cpp/locale/codecvt_utf16"> +std::codecvt_utf16</a>, and +<a href="http://en.cppreference.com/w/cpp/locale/codecvt_utf8_utf16"> +std::codecvt_utf8_utf16</a> +</td> +<td>Non-UTF-8 text is banned by the +<a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Non-ASCII_Characters"> +C++ Style Guide</a>. However, may be useful for +consuming non-ASCII data.</td> +</tr> + +</tbody> +</table> + +</details> + +</div> +</body> +</html> diff --git a/styleguide/c++/chromium-cpp/app.yaml b/styleguide/c++/chromium-cpp/app.yaml new file mode 100644 index 0000000..669b1a0 --- /dev/null +++ b/styleguide/c++/chromium-cpp/app.yaml @@ -0,0 +1,17 @@ +application: chromium-cpp +version: 1 +runtime: python27 +api_version: 1 +threadsafe: yes + +handlers: +- url: /favicon\.ico + static_files: favicon.ico + upload: favicon\.ico + +- url: .* + script: main.app + +libraries: +- name: webapp2 + version: "2.5.2" diff --git a/styleguide/c++/chromium-cpp/favicon.ico b/styleguide/c++/chromium-cpp/favicon.ico Binary files differnew file mode 100644 index 0000000..23c553a2 --- /dev/null +++ b/styleguide/c++/chromium-cpp/favicon.ico diff --git a/styleguide/c++/chromium-cpp/index.yaml b/styleguide/c++/chromium-cpp/index.yaml new file mode 100644 index 0000000..8e6046d --- /dev/null +++ b/styleguide/c++/chromium-cpp/index.yaml @@ -0,0 +1,12 @@ +indexes: + +# AUTOGENERATED + +# This index.yaml is automatically updated whenever the dev_appserver +# detects that a new type of query is run. If you want to manage the +# index.yaml file manually, remove the above marker line (the line +# saying "# AUTOGENERATED"). If you want to manage some indexes +# manually, move them above the marker line. The index.yaml file is +# automatically uploaded to the admin console when you next deploy +# your application using appcfg.py. + diff --git a/styleguide/c++/chromium-cpp/main.py b/styleguide/c++/chromium-cpp/main.py new file mode 100755 index 0000000..9017296 --- /dev/null +++ b/styleguide/c++/chromium-cpp/main.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +from google.appengine.api import memcache +from google.appengine.api import urlfetch +import webapp2 + +import base64 + +"""A simple appengine app that hosts .html files in src/styleguide/c++ from +chromium's git repo.""" + + +class MainHandler(webapp2.RequestHandler): + def get(self): + handler = GitilesMirrorHandler() + handler.initialize(self.request, self.response) + return handler.get("c++11.html") + + +BASE = 'https://chromium.googlesource.com/chromium/src.git/' \ + '+/master/styleguide/c++/%s?format=TEXT' +class GitilesMirrorHandler(webapp2.RequestHandler): + def get(self, resource): + if '..' in resource: # No path traversal. + self.response.write(':-(') + return + + url = BASE % resource + contents = memcache.get(url) + if not contents or self.request.get('bust'): + result = urlfetch.fetch(url) + if result.status_code != 200: + self.response.write('http error %d' % result.status_code) + return + contents = base64.b64decode(result.content) + memcache.set(url, contents, time=5*60) # seconds + + if resource.endswith('.css'): + self.response.headers['Content-Type'] = 'text/css' + self.response.write(contents) + + +app = webapp2.WSGIApplication([ + ('/', MainHandler), + ('/(\S+\.(?:css|html))', GitilesMirrorHandler), +], debug=True) |