Skip to content

Commit 334e7e8

Browse files
author
Colin Robertson
committed
Fix remaining whitespace issues
1 parent 2e11c73 commit 334e7e8

File tree

115 files changed

+7425
-6749
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+7425
-6749
lines changed

docs/cppcx/array-and-writeonlyarray-c-cx.md

Lines changed: 83 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10,79 +10,88 @@ ms.author: "mblome"
1010
ms.workload: ["cplusplus"]
1111
---
1212
# Array and WriteOnlyArray (C++/CX)
13-
You can freely use regular C-style arrays or [std::array](../standard-library/array-class-stl.md) in a C++/CX program (although [std::vector](../standard-library/vector-class.md) is often a better choice), but in any API that is published in metadata, you must convert a C-style array or vector to a [Platform::Array](../cppcx/platform-array-class.md) or [Platform::WriteOnlyArray](../cppcx/platform-writeonlyarray-class.md) type depending on how it is being used. The [Platform::Array](../cppcx/platform-array-class.md) type is neither as efficient nor as powerful as [std::vector](../standard-library/vector-class.md), so as a general guideline you should avoid its use in internal code that performs lots of operations on the array elements.
14-
15-
The following array types can be passed across the ABI:
16-
17-
1. const Platform::Array^
18-
19-
2. Platform::Array^*
20-
21-
3. Platform::WriteOnlyArray
22-
23-
4. return value of Platform::Array^
24-
25-
You use these array types to implement the three kinds of array patterns that are defined by the Windows Runtime.
26-
27-
PassArray
28-
Used when the caller passes an array to a method. The C++ input parameter type is `const`[Platform::Array](../cppcx/platform-array-class.md)\<T>.
29-
30-
FillArray
31-
Used when the caller passes an array for the method to fill. The C++ input parameter type is [Platform::WriteOnlyArray](../cppcx/platform-writeonlyarray-class.md)\<T>.
32-
33-
ReceiveArray
34-
Used when the caller receives an array that the method allocates. In C++/CX you can return the array in the return value as an Array^ or you can return it as an out parameter as type Array^*.
35-
36-
## PassArray pattern
37-
When client code passes an array to a C++ method and the method does not modify it, the method accepts the array as a const Array^. At the Windows Runtime application binary interface (ABI) level, this is known as a PassArray. The next example shows how to pass an array that's allocated in JavaScript to a C++ function that reads from it.
38-
39-
[!code-javascript[cx_arrays#101](../cppcx/codesnippet/JavaScript/array-and-writeonlyarray-c-_1.js)]
40-
41-
The following snippet shows the C++ method:
42-
43-
[!code-cpp[cx_arrays#01](../cppcx/codesnippet/CPP/js-array/class1.cpp#01)]
44-
45-
## ReceiveArray pattern
46-
In the ReceiveArray pattern, client code declares an array and passes it to a method which allocates the memory for it and initializes it. The C++ input parameter type is a pointer-to-hat: `Array<T>^*`. The following example shows how to declare an array object in JavaScript, and pass it to a C++ function that allocates the memory, initializes the elements, and returns it to JavaScript. JavaScript treats the allocated array as a return value, but the C++ function treats it as an out parameter.
47-
48-
[!code-javascript[cx_arrays#102](../cppcx/codesnippet/JavaScript/array-and-writeonlyarray-c-_3.js)]
49-
50-
The following snippet shows two ways to implement the C++ method:
51-
52-
[!code-cpp[cx_arrays#02](../cppcx/codesnippet/CPP/js-array/class1.cpp#02)]
53-
54-
## Fill arrays
55-
When you want to allocate an array in the caller, and initialize or modify it in the callee, use `WriteOnlyArray`. The next example shows how to implement a C++ function that uses `WriteOnlyArray` and call it from JavaScript.
56-
57-
[!code-javascript[cx_arrays#103](../cppcx/codesnippet/JavaScript/array-and-writeonlyarray-c-_5.js)]
58-
59-
The following snippet shows how to implement the C++ method:
60-
61-
[!code-cpp[cx_arrays#03](../cppcx/codesnippet/CPP/js-array/class1.cpp#03)]
62-
63-
## Array conversions
64-
This example shows how to use a [Platform::Array](../cppcx/platform-array-class.md) to construct other kinds of collections:
65-
66-
[!code-cpp[cx_arrays#05](../cppcx/codesnippet/CPP/js-array/class1.cpp#05)]
67-
68-
The next example shows how to construct a [Platform::Array](../cppcx/platform-array-class.md) from a C-style array and return it from a public method.
69-
70-
[!code-cpp[cx_arrays#06](../cppcx/codesnippet/CPP/js-array/class1.cpp#06)]
71-
72-
## Jagged arrays
73-
The Windows Runtime type system does not support the concept of jagged arrays and therefore you cannot use `IVector<Platform::Array<T>>` as a return value or method parameter in a public method. To pass a jagged array or a sequence of sequences across the ABI, use `IVector<IVector<T>^>`.
74-
75-
## Use ArrayReference to avoid copying data
76-
In some scenarios where data is being passed across the ABI into a [Platform::Array](../cppcx/platform-array-class.md), and you ultimately want to process that data in a C-style array for efficiency, you can use [Platform::ArrayReference](../cppcx/platform-arrayreference-class.md) to avoid the extra copy operation. When you pass a [Platform::ArrayReference](../cppcx/platform-arrayreference-class.md) as an argument to a parameter that takes a `Platform::Array`, the `ArrayReference` will store the data directly into a C-style array that you specify. Just be aware that `ArrayReference` has no lock on the source data, so if it that data is modified or deleted on another thread before the call completes, the results will be undefined.
77-
78-
The following code snippet shows how to copy the results of a [DataReader](https://msdn.microsoft.com/library/windows/apps/windows.storage.streams.datareader.aspx) operation into a `Platform::Array` (the usual pattern), and then how to substitute `ArrayReference` to copy the data directly into a C-style array:
79-
80-
[!code-cpp[cx_arrays#07](../cppcx/codesnippet/CPP/js-array/class1.h#07)]
81-
82-
## Avoid exposing an Array as a property
83-
In general, you should avoid exposing a `Platform::Array` type as a property in a ref class because the entire array is returned even when client code is only attempting to access a single element. When you need to expose a sequence container as a property in a public ref class, [Windows::Foundation::IVector](https://msdn.microsoft.com/library/windows/apps/br206631.aspx) is a better choice. In private or internal APIs (which are not published to metadata), consider using a standard C++ container such as [std::vector](../standard-library/vector-class.md).
84-
85-
## See Also
86-
[Type System](../cppcx/type-system-c-cx.md)<br/>
13+
14+
You can freely use regular C-style arrays or [std::array](../standard-library/array-class-stl.md) in a C++/CX program (although [std::vector](../standard-library/vector-class.md) is often a better choice), but in any API that is published in metadata, you must convert a C-style array or vector to a [Platform::Array](../cppcx/platform-array-class.md) or [Platform::WriteOnlyArray](../cppcx/platform-writeonlyarray-class.md) type depending on how it is being used. The [Platform::Array](../cppcx/platform-array-class.md) type is neither as efficient nor as powerful as [std::vector](../standard-library/vector-class.md), so as a general guideline you should avoid its use in internal code that performs lots of operations on the array elements.
15+
16+
The following array types can be passed across the ABI:
17+
18+
1. const Platform::Array^
19+
20+
1. Platform::Array^*
21+
22+
1. Platform::WriteOnlyArray
23+
24+
1. return value of Platform::Array^
25+
26+
You use these array types to implement the three kinds of array patterns that are defined by the Windows Runtime.
27+
28+
PassArray
29+
Used when the caller passes an array to a method. The C++ input parameter type is `const`[Platform::Array](../cppcx/platform-array-class.md)\<T>.
30+
31+
FillArray
32+
Used when the caller passes an array for the method to fill. The C++ input parameter type is [Platform::WriteOnlyArray](../cppcx/platform-writeonlyarray-class.md)\<T>.
33+
34+
ReceiveArray
35+
Used when the caller receives an array that the method allocates. In C++/CX you can return the array in the return value as an Array^ or you can return it as an out parameter as type Array^*.
36+
37+
## PassArray pattern
38+
39+
When client code passes an array to a C++ method and the method does not modify it, the method accepts the array as a const Array^. At the Windows Runtime application binary interface (ABI) level, this is known as a PassArray. The next example shows how to pass an array that's allocated in JavaScript to a C++ function that reads from it.
40+
41+
[!code-javascript[cx_arrays#101](../cppcx/codesnippet/JavaScript/array-and-writeonlyarray-c-_1.js)]
42+
43+
The following snippet shows the C++ method:
44+
45+
[!code-cpp[cx_arrays#01](../cppcx/codesnippet/CPP/js-array/class1.cpp#01)]
46+
47+
## ReceiveArray pattern
48+
49+
In the ReceiveArray pattern, client code declares an array and passes it to a method which allocates the memory for it and initializes it. The C++ input parameter type is a pointer-to-hat: `Array<T>^*`. The following example shows how to declare an array object in JavaScript, and pass it to a C++ function that allocates the memory, initializes the elements, and returns it to JavaScript. JavaScript treats the allocated array as a return value, but the C++ function treats it as an out parameter.
50+
51+
[!code-javascript[cx_arrays#102](../cppcx/codesnippet/JavaScript/array-and-writeonlyarray-c-_3.js)]
52+
53+
The following snippet shows two ways to implement the C++ method:
54+
55+
[!code-cpp[cx_arrays#02](../cppcx/codesnippet/CPP/js-array/class1.cpp#02)]
56+
57+
## Fill arrays
58+
59+
When you want to allocate an array in the caller, and initialize or modify it in the callee, use `WriteOnlyArray`. The next example shows how to implement a C++ function that uses `WriteOnlyArray` and call it from JavaScript.
60+
61+
[!code-javascript[cx_arrays#103](../cppcx/codesnippet/JavaScript/array-and-writeonlyarray-c-_5.js)]
62+
63+
The following snippet shows how to implement the C++ method:
64+
65+
[!code-cpp[cx_arrays#03](../cppcx/codesnippet/CPP/js-array/class1.cpp#03)]
66+
67+
## Array conversions
68+
69+
This example shows how to use a [Platform::Array](../cppcx/platform-array-class.md) to construct other kinds of collections:
70+
71+
[!code-cpp[cx_arrays#05](../cppcx/codesnippet/CPP/js-array/class1.cpp#05)]
72+
73+
The next example shows how to construct a [Platform::Array](../cppcx/platform-array-class.md) from a C-style array and return it from a public method.
74+
75+
[!code-cpp[cx_arrays#06](../cppcx/codesnippet/CPP/js-array/class1.cpp#06)]
76+
77+
## Jagged arrays
78+
79+
The Windows Runtime type system does not support the concept of jagged arrays and therefore you cannot use `IVector<Platform::Array<T>>` as a return value or method parameter in a public method. To pass a jagged array or a sequence of sequences across the ABI, use `IVector<IVector<T>^>`.
80+
81+
## Use ArrayReference to avoid copying data
82+
83+
In some scenarios where data is being passed across the ABI into a [Platform::Array](../cppcx/platform-array-class.md), and you ultimately want to process that data in a C-style array for efficiency, you can use [Platform::ArrayReference](../cppcx/platform-arrayreference-class.md) to avoid the extra copy operation. When you pass a [Platform::ArrayReference](../cppcx/platform-arrayreference-class.md) as an argument to a parameter that takes a `Platform::Array`, the `ArrayReference` will store the data directly into a C-style array that you specify. Just be aware that `ArrayReference` has no lock on the source data, so if it that data is modified or deleted on another thread before the call completes, the results will be undefined.
84+
85+
The following code snippet shows how to copy the results of a [DataReader](https://msdn.microsoft.com/library/windows/apps/windows.storage.streams.datareader.aspx) operation into a `Platform::Array` (the usual pattern), and then how to substitute `ArrayReference` to copy the data directly into a C-style array:
86+
87+
[!code-cpp[cx_arrays#07](../cppcx/codesnippet/CPP/js-array/class1.h#07)]
88+
89+
## Avoid exposing an Array as a property
90+
91+
In general, you should avoid exposing a `Platform::Array` type as a property in a ref class because the entire array is returned even when client code is only attempting to access a single element. When you need to expose a sequence container as a property in a public ref class, [Windows::Foundation::IVector](https://msdn.microsoft.com/library/windows/apps/br206631.aspx) is a better choice. In private or internal APIs (which are not published to metadata), consider using a standard C++ container such as [std::vector](../standard-library/vector-class.md).
92+
93+
## See Also
94+
95+
[Type System](../cppcx/type-system-c-cx.md)<br/>
8796
[Visual C++ Language Reference](../cppcx/visual-c-language-reference-c-cx.md)<br/>
8897
[Namespaces Reference](../cppcx/namespaces-reference-c-cx.md)

docs/cppcx/attributes-c-cx.md

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,41 @@ ms.author: "mblome"
1010
ms.workload: ["cplusplus"]
1111
---
1212
# Attributes (C++/CX)
13-
An attribute is a special kind of ref class that can be prepended in square brackets to Windows Runtime types and methods to specify certain behaviors in metadata creation. Several predefined attributes—for example, [Windows::Foundation::Metadata::WebHostHidden](https://msdn.microsoft.com/library/windows/apps/windows.foundation.metadata.webhosthiddenattribute.aspx)—are commonly used in C++/CX code. This example shows how the attribute is applied to a class:
14-
15-
[!code-cpp[cx_attributes#01](../cppcx/codesnippet/CPP/cx_attributes/class1.h#01)]
16-
17-
## Custom attributes
18-
You can also define custom attributes. Custom attributes must conform to these Windows Runtime rules:
19-
20-
- Custom attributes can contain only public fields.
21-
22-
- Custom attribute fields can be initialized when the attribute is applied to a class.
23-
24-
- A field may be one of these types:
25-
26-
- int32 (int)
27-
28-
- uint32 (unsigned int)
29-
30-
- bool
31-
32-
- Platform::String^
33-
34-
- Windows::Foundation::HResult
35-
36-
- Platform::Type^
37-
38-
- public enum class (includes user-defined enums)
39-
40-
The next example shows how to define a custom attribute and then initialize it when you use it.
41-
42-
[!code-cpp[cx_attributes#02](../cppcx/codesnippet/CPP/cx_attributes/class1.h#02)]
43-
44-
## See Also
45-
[Type System (C++/CX)](../cppcx/type-system-c-cx.md)<br/>
13+
14+
An attribute is a special kind of ref class that can be prepended in square brackets to Windows Runtime types and methods to specify certain behaviors in metadata creation. Several predefined attributes—for example, [Windows::Foundation::Metadata::WebHostHidden](https://msdn.microsoft.com/library/windows/apps/windows.foundation.metadata.webhosthiddenattribute.aspx)—are commonly used in C++/CX code. This example shows how the attribute is applied to a class:
15+
16+
[!code-cpp[cx_attributes#01](../cppcx/codesnippet/CPP/cx_attributes/class1.h#01)]
17+
18+
## Custom attributes
19+
20+
You can also define custom attributes. Custom attributes must conform to these Windows Runtime rules:
21+
22+
- Custom attributes can contain only public fields.
23+
24+
- Custom attribute fields can be initialized when the attribute is applied to a class.
25+
26+
- A field may be one of these types:
27+
28+
- int32 (int)
29+
30+
- uint32 (unsigned int)
31+
32+
- bool
33+
34+
- Platform::String^
35+
36+
- Windows::Foundation::HResult
37+
38+
- Platform::Type^
39+
40+
- public enum class (includes user-defined enums)
41+
42+
The next example shows how to define a custom attribute and then initialize it when you use it.
43+
44+
[!code-cpp[cx_attributes#02](../cppcx/codesnippet/CPP/cx_attributes/class1.h#02)]
45+
46+
## See Also
47+
48+
[Type System (C++/CX)](../cppcx/type-system-c-cx.md)<br/>
4649
[Visual C++ Language Reference](../cppcx/visual-c-language-reference-c-cx.md)<br/>
4750
[Namespaces Reference](../cppcx/namespaces-reference-c-cx.md)

docs/cppcx/back-inserter-function.md

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,40 @@ ms.author: "mblome"
1313
ms.workload: ["cplusplus"]
1414
---
1515
# back_inserter Function
16-
Returns an iterator that is used to insert elements at the end of the specified collection.
17-
18-
## Syntax
19-
20-
```
21-
16+
17+
Returns an iterator that is used to insert elements at the end of the specified collection.
18+
19+
## Syntax
20+
21+
```
22+
2223
template <typename T>
23-
Platform::BackInsertIterator<T>
24-
back_inserter(IVector<T>^ v);
25-
26-
template<typename T>
27-
Platform::BackInsertIterator<T>
28-
back_inserter(IObservableVector<T>^ v);
29-
```
30-
31-
#### Parameters
24+
Platform::BackInsertIterator<T>
25+
back_inserter(IVector<T>^ v);
26+
27+
template<typename T>
28+
Platform::BackInsertIterator<T>
29+
back_inserter(IObservableVector<T>^ v);
30+
```
31+
32+
#### Parameters
33+
3234
*T*<br/>
33-
A template type parameter.
34-
35+
A template type parameter.
36+
3537
*v*<br/>
36-
An interface pointer that provides access to the underlying collection.
37-
38-
### Return Value
39-
An iterator.
40-
41-
### Requirements
42-
**Header:** collection.h
43-
44-
**Namespace:** Windows::Foundation::Collections
45-
46-
## See Also
47-
[Windows::Foundation::Collections Namespace](../cppcx/windows-foundation-collections-namespace-c-cx.md)
38+
An interface pointer that provides access to the underlying collection.
39+
40+
### Return Value
41+
42+
An iterator.
43+
44+
### Requirements
45+
46+
**Header:** collection.h
47+
48+
**Namespace:** Windows::Foundation::Collections
49+
50+
## See Also
51+
52+
[Windows::Foundation::Collections Namespace](../cppcx/windows-foundation-collections-namespace-c-cx.md)

0 commit comments

Comments
 (0)