Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rejig typeconversionpolicy #1129

Closed
wants to merge 27 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more example
adetaylor committed Jun 22, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 2b9b3c4830836bd30904555029a8f3a8f30fdd78
3 changes: 2 additions & 1 deletion examples/reference-wrappers/build.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,8 @@
fn main() -> miette::Result<()> {
let path = std::path::PathBuf::from("src");
let mut b = autocxx_build::Builder::new("src/main.rs", &[&path]).build()?;
b.flag_if_supported("-std=c++14").compile("autocxx-reference-wrapper-example");
b.flag_if_supported("-std=c++14")
.file("src/input.cc").compile("autocxx-reference-wrapper-example");

println!("cargo:rerun-if-changed=src/main.rs");
println!("cargo:rerun-if-changed=src/input.h");
11 changes: 11 additions & 0 deletions examples/reference-wrappers/src/input.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#include "input.h"

Goat the_goat;
11 changes: 11 additions & 0 deletions examples/reference-wrappers/src/input.h
Original file line number Diff line number Diff line change
@@ -22,10 +22,21 @@ class Goat {
uint32_t horns;
};


inline void Goat::add_a_horn() { horns++; }
inline std::string Goat::describe() const {
std::ostringstream oss;
std::string plural = horns == 1 ? "" : "s";
oss << "This goat has " << horns << " horn" << plural << ".";
return oss.str();
}

class Field {
public:
const Goat& get_goat() const {
return the_goat;
}

private:
Goat the_goat;
};
3 changes: 3 additions & 0 deletions examples/reference-wrappers/src/main.rs
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ include_cpp! {
#include "input.h"
safety!(unsafe_references_wrapped)
generate!("Goat")
generate!("Field")
}

fn main() {
@@ -26,4 +27,6 @@ fn main() {
.to_string_lossy(),
"This goat has 2 horns."
);
let mut field = ffi::Field::new().within_box();
let another_goat = field.get_goat();
}