Skip to content

Commit ad9e125

Browse files
committed
initial commit
0 parents  commit ad9e125

File tree

96 files changed

+19292
-0
lines changed

Some content is hidden

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

96 files changed

+19292
-0
lines changed

.clang-format

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
BasedOnStyle: LLVM
2+
ColumnLimit: 0
3+
DerivePointerBinding: true
4+
AllowShortIfStatementsOnASingleLine: true
5+
AllowShortBlocksOnASingleLine: true
6+
PointerAlignment: Left
7+
IndentCaseLabels: true

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true
10+
11+
[Makefile]
12+
indent_style = tab

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

.markdownlint.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"MD013": false,
3+
"MD030": {
4+
"ol_single": 2,
5+
"ol_multi": 2
6+
},
7+
"MD033": {
8+
"allowed_elements": ["br"]
9+
},
10+
"MD041": false
11+
}

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: cpp
2+
os: osx
3+
compiler: clang
4+
install: true
5+
script: make -C tests

.vscode/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/browse.vc.db*

.vscode/c_cpp_properties.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Mac",
5+
"browse": {
6+
"path": [
7+
"${workspaceFolder}/include",
8+
"${workspaceFolder}/tests/vendor/include",
9+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++",
10+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
11+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include",
12+
"/opt/local/include",
13+
"/usr/include",
14+
"/usr/include/c++/4.2.1",
15+
"/usr/local/include"
16+
],
17+
"limitSymbolsToIncludedHeaders": true,
18+
"databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db"
19+
},
20+
"defines": [],
21+
"includePath": [
22+
"${workspaceFolder}/include",
23+
"${workspaceFolder}/tests/vendor/include",
24+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++",
25+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
26+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include",
27+
"/opt/local/include",
28+
"/usr/include",
29+
"/usr/include/c++/4.2.1",
30+
"/usr/local/include"
31+
],
32+
"macFrameworkPath": []
33+
}
34+
],
35+
"version": 4
36+
}

.vscode/settings.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"files.exclude": {
3+
"**/build/": true,
4+
"**/vendor/cget/": true,
5+
".vscode/browse.vc.*": true
6+
},
7+
"search.exclude": {
8+
"**/vendor/": true
9+
}
10+
}

LICENSE.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Boost Software License - Version 1.0 - August 17th, 2003
2+
3+
Permission is hereby granted, free of charge, to any person or organization
4+
obtaining a copy of the software and accompanying documentation covered by
5+
this license (the "Software") to use, reproduce, display, distribute,
6+
execute, and transmit the Software, and to prepare derivative works of the
7+
Software, and to permit third-parties to whom the Software is furnished to
8+
do so, all subject to the following:
9+
10+
The copyright notices in the Software and this entire statement, including
11+
the above license grant, this restriction and the following disclaimer,
12+
must be included in all copies of the Software, in whole or in part, and
13+
all derivative works of the Software, unless such copies or derivative
14+
works are solely in the form of machine-executable object code generated by
15+
a source language processor.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[![Build Status](https://travis-ci.org/pqrs-org/cpp-thread_wait.svg?branch=master)](https://travis-ci.org/pqrs-org/cpp-thread_wait)
2+
[![License](https://img.shields.io/badge/license-Boost%20Software%20License-blue.svg)](https://github.com/pqrs-org/cpp-thread-wait/blob/master/LICENSE.md)
3+
4+
# cpp-osx-cf_ptr
5+
6+
A smart pointer of `CFTypeRef`.
7+
8+
## Install
9+
10+
### Manual install
11+
12+
Copy `include/pqrs` directory into your include directory.
13+
14+
### Using package manager
15+
16+
You can also install `include/pqrs` by using [cget](https://github.com/pfultz2/cget).
17+
18+
```shell
19+
cget install pqrs-org/[email protected] --cmake header
20+
```
21+
22+
## Usage
23+
24+
```cpp
25+
```

example/CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required (VERSION 3.9)
2+
3+
set(CMAKE_CXX_STANDARD 14)
4+
5+
add_compile_options(-Wall)
6+
add_compile_options(-Werror)
7+
add_compile_options(-O2)
8+
9+
project (example)
10+
11+
include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../include)
12+
13+
add_executable(
14+
example
15+
main.cpp
16+
)
17+
18+
target_link_libraries(
19+
example
20+
"-framework CoreFoundation"
21+
)

example/Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
all:
2+
mkdir -p build \
3+
&& cd build \
4+
&& cmake .. \
5+
&& make
6+
7+
clean:
8+
rm -r build
9+
10+
run:
11+
./build/example

example/main.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <iostream>
2+
#include <pqrs/cf_ptr.hpp>
3+
4+
int main(void) {
5+
{
6+
pqrs::cf_ptr<CFStringRef> p;
7+
8+
if (auto string = CFStringCreateWithCString(kCFAllocatorDefault,
9+
"example",
10+
kCFStringEncodingUTF8)) {
11+
p = string;
12+
13+
CFRelease(string);
14+
}
15+
16+
std::cout << CFGetRetainCount(*p) << std::endl; // CFGetRetainCount(*p) == 1
17+
std::cout << CFStringGetCStringPtr(*p, kCFStringEncodingUTF8) << std::endl;
18+
}
19+
20+
return 0;
21+
}

include/pqrs/cf_ptr.hpp

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#pragma once
2+
3+
#include <CoreFoundation/CoreFoundation.h>
4+
5+
namespace pqrs {
6+
template <typename T>
7+
class cf_ptr final {
8+
public:
9+
cf_ptr(void) : cf_ptr(nullptr) {
10+
}
11+
12+
cf_ptr(T _Nullable p) : p_(p) {
13+
if (p_) {
14+
CFRetain(p_);
15+
}
16+
}
17+
18+
cf_ptr(const cf_ptr& other) : p_(nullptr) {
19+
*this = other;
20+
}
21+
22+
cf_ptr& operator=(const cf_ptr& other) {
23+
auto old = p_;
24+
25+
p_ = other.p_;
26+
if (p_) {
27+
CFRetain(p_);
28+
}
29+
30+
if (old) {
31+
CFRelease(old);
32+
}
33+
34+
return *this;
35+
}
36+
37+
~cf_ptr(void) {
38+
reset();
39+
}
40+
41+
const T& get(void) const {
42+
return p_;
43+
}
44+
45+
T& get(void) {
46+
return const_cast<T&>((static_cast<const cf_ptr&>(*this)).get());
47+
}
48+
49+
void reset(void) {
50+
if (p_) {
51+
CFRelease(p_);
52+
p_ = nullptr;
53+
}
54+
}
55+
56+
operator bool(void) const {
57+
return p_ != nullptr;
58+
}
59+
60+
const T& operator*(void)const {
61+
return p_;
62+
}
63+
64+
T& operator*(void) {
65+
return const_cast<T&>(*(static_cast<const cf_ptr&>(*this)));
66+
}
67+
68+
private:
69+
T _Nullable p_;
70+
};
71+
} // namespace pqrs

tests/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/cget/cget.cmake
2+
/vendor/**/pkgconfig/

tests/Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
all:
2+
@for d in `find * -type d`; do \
3+
if [ -f "$$d/Makefile" ]; then \
4+
echo "[Test] $$d"; \
5+
make -C $$d || exit 1; \
6+
fi; \
7+
done
8+
9+
clean:
10+
@for d in `find * -type d`; do \
11+
if [ -f "$$d/Makefile" ]; then \
12+
make -C $$d clean; \
13+
fi; \
14+
done
15+
16+
update_vendor:
17+
cget install -f cget-requirements.txt --prefix vendor

tests/cget-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/src/CMakeLists.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cmake_minimum_required (VERSION 3.9)
2+
3+
set(CMAKE_CXX_STANDARD 14)
4+
5+
add_compile_options(-Wall)
6+
add_compile_options(-Werror)
7+
add_compile_options(-O2)
8+
9+
include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../../include)
10+
include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../vendor/include)
11+
12+
project (test)
13+
14+
add_executable(
15+
test
16+
test.cpp
17+
)
18+
19+
target_link_libraries(
20+
test
21+
"-framework CoreFoundation"
22+
)

tests/src/Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
all:
2+
mkdir -p build \
3+
&& cd build \
4+
&& cmake .. \
5+
&& make
6+
make run
7+
8+
clean:
9+
rm -r build
10+
11+
run:
12+
./build/test

0 commit comments

Comments
 (0)