本文整理汇总了C++中Shared类的典型用法代码示例。如果您正苦于以下问题:C++ Shared类的具体用法?C++ Shared怎么用?C++ Shared使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Shared类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LogBuffer
Ref<Image> Image::load_from_data (const Ptr<IData> data) {
static Stopwatch t;
static unsigned count = 0; ++count;
Ref<Image> loaded_image;
Shared<Buffer> buffer;
t.start();
buffer = data->buffer();
switch (buffer->mimetype()) {
case IMAGE_JPEG:
loaded_image = load_jpeg_image(data);
break;
case IMAGE_PNG:
loaded_image = load_png_image(data);
break;
//case Data::IMAGE_DDS:
// loaded_image = load_ddsimage(data);
default:
logger()->log(LOG_ERROR, "Could not load image: Unsupported image format.");
}
t.pause();
logger()->log(LOG_INFO, LogBuffer() << "*** Total time to load " << count << " images: " << t.time() << "s");
return loaded_image;
}
示例2: ns2ClassA_memberFunction_9
void ns2ClassA_memberFunction_9(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
typedef boost::shared_ptr<ns2::ClassA> Shared;
checkArguments("memberFunction",nargout,nargin-1,0);
Shared obj = unwrap_shared_ptr<ns2::ClassA>(in[0], "ptr_ns2ClassA");
out[0] = wrap< double >(obj->memberFunction());
}
示例3: SaveToFile
CC_FILE_ERROR FileIOFilter::SaveToFile( ccHObject* entities,
const QString& filename,
SaveParameters& parameters,
Shared filter)
{
if (!entities || filename.isEmpty() || !filter)
return CC_FERR_BAD_ARGUMENT;
//if the file name has no extension, we had a default one!
QString completeFileName(filename);
if (QFileInfo(filename).suffix().isEmpty())
completeFileName += QString(".%1").arg(filter->getDefaultExtension());
CC_FILE_ERROR result = CC_FERR_NO_ERROR;
try
{
result = filter->saveToFile(entities, completeFileName, parameters);
}
catch(...)
{
ccLog::Warning(QString("[I/O] CC has caught an unhandled exception while saving file '%1'").arg(filename));
result = CC_FERR_CONSOLE_ERROR;
}
if (result == CC_FERR_NO_ERROR)
{
ccLog::Print(QString("[I/O] File '%1' saved successfully").arg(filename));
}
else
{
DisplayErrorMessage(result,"saving",filename);
}
return result;
}
示例4: main
int main()
{
Shared<Car> a;
auto age1 = a.execute([](Car & c) -> unsigned { return c.increment_age(); });
auto age2 = a.execute([](Car & c) -> unsigned { return c.increment_age(); });
auto age3 = a.execute([](Car & c) -> unsigned { return c.increment_age(); });
std::cout << age1.get() << ", " << age2.get() << ", " << age3.get() << std::endl;
}
示例5: ns2ClassA_nsArg_10
void ns2ClassA_nsArg_10(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
typedef boost::shared_ptr<ns2::ClassA> Shared;
checkArguments("nsArg",nargout,nargin-1,1);
Shared obj = unwrap_shared_ptr<ns2::ClassA>(in[0], "ptr_ns2ClassA");
ns1::ClassB& arg = *unwrap_shared_ptr< ns1::ClassB >(in[1], "ptr_ns1ClassB");
out[0] = wrap< int >(obj->nsArg(arg));
}
示例6:
/// Create a buffer from a given input stream
BufferedData::BufferedData (std::istream & stream)
{
Shared<DynamicBuffer> buffer = new DynamicBuffer;
buffer->append(std::istreambuf_iterator<char>(stream), std::istreambuf_iterator<char>());
_buffer = buffer;
}
示例7: ns2ClassA_nsReturn_11
void ns2ClassA_nsReturn_11(int nargout, mxArray *out[], int nargin, const mxArray *in[])
{
typedef boost::shared_ptr<ns2::ns3::ClassB> SharedClassB;
typedef boost::shared_ptr<ns2::ClassA> Shared;
checkArguments("nsReturn",nargout,nargin-1,1);
Shared obj = unwrap_shared_ptr<ns2::ClassA>(in[0], "ptr_ns2ClassA");
double q = unwrap< double >(in[1]);
out[0] = wrap_shared_ptr(SharedClassB(new ns2::ns3::ClassB(obj->nsReturn(q))),"ns2.ns3.ClassB", false);
}
示例8: deserialize
void Dictionary::deserialize (Ref<IData> data)
{
Shared<Buffer> buffer = data->buffer();
std::size_t offset = 0;
while (offset < buffer->size()) {
KeyT key = TypeSerialization<TI_STRING>::read_from_buffer(*buffer, offset);
_values[key] = Value::read_from_buffer(*buffer, offset);
}
}
示例9: load_jpeg_image
static Ref<Image> load_jpeg_image (const Ptr<IData> data) {
jpeg_decompress_struct cinfo;
jpeg_error_mgr jerr;
Ref<Image> result_image;
DataType data_type = DataType::BYTE;
Shared<Buffer> buffer = data->buffer();
unsigned width, height;
try {
//memset (&cinfo, 0, sizeof (cinfo));
memset (&jerr, 0, sizeof (jerr));
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_memory_src(&cinfo, buffer->begin(), buffer->size());
jpeg_read_header(&cinfo, TRUE);
width = cinfo.image_width;
height = cinfo.image_height;
unsigned row_width = 0;
PixelFormat pixel_format;
if (cinfo.jpeg_color_space == JCS_GRAYSCALE) {
row_width = width;
pixel_format = PixelFormat::L;
} else {
row_width = 3 * width;
pixel_format = PixelFormat::RGB;
}
result_image = new Image(Vec2u(width, height), pixel_format, data_type);
ByteT *line = result_image->data();
jpeg_start_decompress(&cinfo);
// read jpeg image
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, &line, 1);
line += row_width;
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
} catch (std::exception &e) {
}
return result_image;
};
示例10: load_wave_data
Ref<Object> Sound::Loader::load_from_data (const Ptr<IData> data, const ILoader * loader)
{
Shared<Buffer> buffer = data->buffer();
Mimetype mt = buffer->mimetype();
if (mt == AUDIO_XWAV) {
return load_wave_data(data);
} else {
throw LoadError("Could not load audio data");
}
}
示例11: main
int main()
{
Shared shlib;
Static stlib;
std::cout << "Static library subtract(5, 3): ";
std::cout << stlib.subtract(5, 3) << std::endl;
std::cout << "Shared library add(4, 5): ";
std::cout << shlib.add(4, 5) << std::endl;
return EXIT_SUCCESS;
}
示例12: property
Shared<Buffer> Program::info_log() {
GLint length;
property(GL_INFO_LOG_LENGTH, &length);
if (length > 0) {
Shared<MutableBuffer> buffer = PackedBuffer::new_buffer(length);
glGetProgramInfoLog(_handle, length, NULL, (GLchar *)buffer->begin());
return buffer;
} else {
return NULL;
}
}
示例13:
Shared<ui::Font> FontAsset::createFont() const
{
Shared<Texture2D> atlasTex = Shared<Texture2D>::alloc();
atlasTex->alloc();
atlasTex->set_texels(atlas, 0);
return Shared<ui::Font>::alloc(
std::move(atlasTex),
entries,
defaultEntry,
lineHeight,
tabWidth,
spaceWidth);
}
示例14: init
void init(
const Shared & shared,
const Group & group,
rng_t & rng) {
Shared post = shared.plus_group(group);
mean = sample_gamma(rng, post.alpha, 1.f / post.inv_beta);
}
示例15: init
void init(
const Shared & shared,
const Group & group,
rng_t & rng) {
Shared post = shared.plus_group(group);
beta = sample_beta(rng, post.alpha, post.beta);
}