本文整理汇总了C++中containers::Array类的典型用法代码示例。如果您正苦于以下问题:C++ Array类的具体用法?C++ Array怎么用?C++ Array使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Array类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: encode
crimild::Bool encode( std::string key, containers::Array< T, U > &a )
{
crimild::Size N = a.size();
encodeArrayBegin( key, N );
a.each( [ this, key ]( T &elem, crimild::Size i ) {
auto itemKey = beginEncodingArrayElement( key, i );
encode( itemKey, elem );
endEncodingArrayElement( key, i );
});
encodeArrayEnd( key );
return true;
}
开发者ID:hhsaez,项目名称:crimild,代码行数:15,代码来源:Encoder.hpp
示例2: mapRangeExplicitFlush
void BufferGLTest::mapRangeExplicitFlush() {
#ifndef MAGNUM_TARGET_GLES2
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::map_buffer_range>())
CORRADE_SKIP(Extensions::GL::ARB::map_buffer_range::string() + std::string(" is not supported"));
#else
if(!Context::current()->isExtensionSupported<Extensions::GL::EXT::map_buffer_range>())
CORRADE_SKIP(Extensions::GL::EXT::map_buffer_range::string() + std::string(" is not supported"));
#endif
constexpr char data[] = {2, 7, 5, 13, 25};
Buffer buffer;
buffer.setData(data, Buffer::Usage::StaticDraw);
/* Map, set byte, don't flush and unmap */
char* contents = reinterpret_cast<char*>(buffer.map(1, 4, Buffer::MapFlag::Write|Buffer::MapFlag::FlushExplicit));
CORRADE_VERIFY(contents);
contents[2] = 99;
CORRADE_VERIFY(buffer.unmap());
MAGNUM_VERIFY_NO_ERROR();
/* Unflushed range _might_ not be changed, thus nothing to test */
/* Map, set byte, flush and unmap */
contents = reinterpret_cast<char*>(buffer.map(1, 4, Buffer::MapFlag::Write|Buffer::MapFlag::FlushExplicit));
CORRADE_VERIFY(contents);
contents[3] = 107;
buffer.flushMappedRange(3, 1);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_VERIFY(buffer.unmap());
MAGNUM_VERIFY_NO_ERROR();
/* Flushed range should be changed */
/** @todo How to verify the contents in ES? */
#ifndef MAGNUM_TARGET_GLES
Containers::Array<char> changedContents = buffer.data<char>();
CORRADE_COMPARE(changedContents.size(), 5);
CORRADE_COMPARE(changedContents[4], 107);
#endif
}
开发者ID:awoland,项目名称:magnum,代码行数:39,代码来源:BufferGLTest.cpp
示例3: compressShort
void CompressIndicesTest::compressShort() {
std::size_t indexCount;
Mesh::IndexType indexType;
Containers::Array<char> data;
std::tie(indexCount, indexType, data) = MeshTools::compressIndices(
std::vector<UnsignedInt>{1, 256, 0, 5});
CORRADE_COMPARE(indexCount, 4);
CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedShort);
if(!Utility::Endianness::isBigEndian()) {
CORRADE_COMPARE(std::vector<char>(data.begin(), data.end()),
(std::vector<char>{ 0x01, 0x00,
0x00, 0x01,
0x00, 0x00,
0x05, 0x00 }));
} else {
CORRADE_COMPARE(std::vector<char>(data.begin(), data.end()),
(std::vector<char>{ 0x00, 0x01,
0x01, 0x00,
0x00, 0x00,
0x00, 0x05 }));
}
}
开发者ID:ArEnSc,项目名称:magnum,代码行数:23,代码来源:CompressIndicesTest.cpp
示例4: access
void ArrayTest::access() {
Array a(7);
for(std::size_t i = 0; i != 7; ++i)
a[i] = i;
CORRADE_COMPARE(a.data(), static_cast<int*>(a));
CORRADE_COMPARE(*(a.begin()+2), 2);
CORRADE_COMPARE(a[4], 4);
CORRADE_COMPARE(a.end()-a.begin(), a.size());
const auto b = Array::from(7, 3, 5, 4);
CORRADE_COMPARE(b.data(), static_cast<const int*>(b));
CORRADE_COMPARE(b[2], 5);
}
开发者ID:mdietsch,项目名称:corrade,代码行数:14,代码来源:ArrayTest.cpp
示例5: copy
void BufferGLTest::copy() {
Buffer buffer1;
constexpr char data[] = {2, 7, 5, 13, 25};
buffer1.setData(data, BufferUsage::StaticCopy);
Buffer buffer2;
buffer2.setData({nullptr, 5}, BufferUsage::StaticRead);
Buffer::copy(buffer1, buffer2, 1, 2, 3);
MAGNUM_VERIFY_NO_ERROR();
/** @todo How to verify the contents in ES? */
#ifndef MAGNUM_TARGET_GLES
const Containers::Array<char> subContents = buffer2.subData<char>(2, 3);
CORRADE_COMPARE(subContents.size(), 3);
CORRADE_COMPARE(subContents[0], 7);
CORRADE_COMPARE(subContents[1], 5);
CORRADE_COMPARE(subContents[2], 13);
#endif
}
开发者ID:BrainlessLabsInc,项目名称:magnum,代码行数:20,代码来源:BufferGLTest.cpp
示例6: Error
std::optional<ImageData2D> JpegImporter::doImage2D(UnsignedInt) {
/* Initialize structures */
jpeg_decompress_struct file;
Containers::Array<JSAMPROW> rows;
Containers::Array<char> data;
/* Fugly error handling stuff */
/** @todo Get rid of this crap */
struct ErrorManager {
jpeg_error_mgr jpegErrorManager;
std::jmp_buf setjmpBuffer;
} errorManager;
file.err = jpeg_std_error(&errorManager.jpegErrorManager);
errorManager.jpegErrorManager.error_exit = [](j_common_ptr info) {
info->err->output_message(info);
std::longjmp(reinterpret_cast<ErrorManager*>(info->err)->setjmpBuffer, 1);
};
if(setjmp(errorManager.setjmpBuffer)) {
Error() << "Trade::JpegImporter::image2D(): error while reading JPEG file";
jpeg_destroy_decompress(&file);
return std::nullopt;
}
/* Open file */
jpeg_create_decompress(&file);
jpeg_mem_src(&file, _in.begin(), _in.size());
/* Read file header, start decompression */
jpeg_read_header(&file, true);
jpeg_start_decompress(&file);
/* Image size and type */
const Vector2i size(file.output_width, file.output_height);
static_assert(BITS_IN_JSAMPLE == 8, "Only 8-bit JPEG is supported");
constexpr PixelType type = PixelType::UnsignedByte;
/* Image format */
PixelFormat format = {};
switch(file.out_color_space) {
case JCS_GRAYSCALE:
CORRADE_INTERNAL_ASSERT(file.out_color_components == 1);
#ifdef MAGNUM_TARGET_GLES2
format = Context::hasCurrent() && Context::current().isExtensionSupported<Extensions::GL::EXT::texture_rg>() ?
PixelFormat::Red : PixelFormat::Luminance;
#else
format = PixelFormat::Red;
#endif
break;
case JCS_RGB:
CORRADE_INTERNAL_ASSERT(file.out_color_components == 3);
format = PixelFormat::RGB;
break;
/** @todo RGBA (only in libjpeg-turbo and probably ignored) */
default:
Error() << "Trade::JpegImporter::image2D(): unsupported color space" << file.out_color_space;
return std::nullopt;
}
/* Initialize data array, align rows to four bytes */
const std::size_t stride = ((size.x()*file.out_color_components*BITS_IN_JSAMPLE/8 + 3)/4)*4;
data = Containers::Array<char>{stride*std::size_t(size.y())};
/* Read image row by row */
rows = Containers::Array<JSAMPROW>{std::size_t(size.y())};
for(Int i = 0; i != size.y(); ++i)
rows[i] = reinterpret_cast<JSAMPROW>(data.data()) + (size.y() - i - 1)*stride;
while(file.output_scanline < file.output_height)
jpeg_read_scanlines(&file, rows + file.output_scanline, file.output_height - file.output_scanline);
/* Cleanup */
jpeg_finish_decompress(&file);
jpeg_destroy_decompress(&file);
/* Always using the default 4-byte alignment */
return Trade::ImageData2D{format, type, size, std::move(data)};
}
开发者ID:caomw,项目名称:magnum-plugins,代码行数:79,代码来源:JpegImporter.cpp
示例7: BufferGLTest
namespace Magnum { namespace Test {
struct BufferGLTest: AbstractOpenGLTester {
explicit BufferGLTest();
void construct();
void constructCopy();
void constructMove();
void wrap();
void label();
#ifndef MAGNUM_TARGET_GLES2
void bindBase();
void bindRange();
#endif
void data();
void map();
#ifdef CORRADE_TARGET_NACL
void mapSub();
#endif
void mapRange();
void mapRangeExplicitFlush();
#ifndef MAGNUM_TARGET_GLES2
void copy();
#endif
void invalidate();
};
BufferGLTest::BufferGLTest() {
addTests({&BufferGLTest::construct,
&BufferGLTest::constructCopy,
&BufferGLTest::constructMove,
&BufferGLTest::wrap,
&BufferGLTest::label,
#ifndef MAGNUM_TARGET_GLES2
&BufferGLTest::bindBase,
&BufferGLTest::bindRange,
#endif
&BufferGLTest::data,
&BufferGLTest::map,
#ifdef CORRADE_TARGET_NACL
&BufferGLTest::mapSub,
#endif
&BufferGLTest::mapRange,
&BufferGLTest::mapRangeExplicitFlush,
#ifndef MAGNUM_TARGET_GLES2
&BufferGLTest::copy,
#endif
&BufferGLTest::invalidate});
}
void BufferGLTest::construct() {
{
Buffer buffer;
MAGNUM_VERIFY_NO_ERROR();
CORRADE_VERIFY(buffer.id() > 0);
CORRADE_COMPARE(buffer.targetHint(), Buffer::TargetHint::Array);
CORRADE_COMPARE(buffer.size(), 0);
}
MAGNUM_VERIFY_NO_ERROR();
}
void BufferGLTest::constructCopy() {
CORRADE_VERIFY(!(std::is_constructible<Buffer, const Buffer&>{}));
CORRADE_VERIFY(!(std::is_assignable<Buffer, const Buffer&>{}));
}
void BufferGLTest::constructMove() {
Buffer a;
const Int id = a.id();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_VERIFY(id > 0);
Buffer b(std::move(a));
CORRADE_COMPARE(a.id(), 0);
CORRADE_COMPARE(b.id(), id);
Buffer c;
const Int cId = c.id();
c = std::move(b);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_VERIFY(cId > 0);
CORRADE_COMPARE(b.id(), cId);
CORRADE_COMPARE(c.id(), id);
}
void BufferGLTest::wrap() {
GLuint id;
glGenBuffers(1, &id);
//.........这里部分代码省略.........
开发者ID:BrainlessLabsInc,项目名称:magnum,代码行数:101,代码来源:BufferGLTest.cpp
示例8: data
void BufferGLTest::data() {
Buffer buffer;
/* Plain array */
constexpr Int data[] = {2, 7, 5, 13, 25};
buffer.setData({data, 5}, BufferUsage::StaticDraw);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4);
/* STL vector */
std::vector<Int> data2{2, 7, 5, 13, 25};
buffer.setData(data2, BufferUsage::StaticDraw);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4);
/* STL array */
std::array<Int, 5> data3{{2, 7, 5, 13, 25}};
buffer.setData(data3, BufferUsage::StaticDraw);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4);
/** @todo How to verify the contents in ES? */
#ifndef MAGNUM_TARGET_GLES
const Containers::Array<Int> contents = buffer.data<Int>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(contents.size(), 5);
CORRADE_COMPARE(contents[0], 2);
CORRADE_COMPARE(contents[1], 7);
CORRADE_COMPARE(contents[2], 5);
CORRADE_COMPARE(contents[3], 13);
CORRADE_COMPARE(contents[4], 25);
#endif
/* Plain array */
constexpr Int subData[] = {125, 3, 15};
buffer.setSubData(4, {subData, 3});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4);
/* STL vector */
std::vector<Int> subData2{125, 3, 15};
buffer.setSubData(4, subData2);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4);
/* STL array */
std::array<Int, 3> subData3{{125, 3, 15}};
buffer.setSubData(4, subData3);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4);
/** @todo How to verify the contents in ES? */
#ifndef MAGNUM_TARGET_GLES
const Containers::Array<Int> subContents = buffer.subData<Int>(4, 3);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(subContents.size(), 3);
CORRADE_COMPARE(subContents[0], 125);
CORRADE_COMPARE(subContents[1], 3);
CORRADE_COMPARE(subContents[2], 15);
#endif
}
开发者ID:BrainlessLabsInc,项目名称:magnum,代码行数:61,代码来源:BufferGLTest.cpp
示例9: Error
Containers::Optional<ImageData2D> JpegImporter::doImage2D(UnsignedInt) {
/* Initialize structures */
jpeg_decompress_struct file;
Containers::Array<char> data;
/* Fugly error handling stuff */
/** @todo Get rid of this crap */
struct ErrorManager {
jpeg_error_mgr jpegErrorManager;
std::jmp_buf setjmpBuffer;
char message[JMSG_LENGTH_MAX]{};
} errorManager;
file.err = jpeg_std_error(&errorManager.jpegErrorManager);
errorManager.jpegErrorManager.error_exit = [](j_common_ptr info) {
auto& errorManager = *reinterpret_cast<ErrorManager*>(info->err);
info->err->format_message(info, errorManager.message);
std::longjmp(errorManager.setjmpBuffer, 1);
};
if(setjmp(errorManager.setjmpBuffer)) {
Error() << "Trade::JpegImporter::image2D(): error:" << errorManager.message;
jpeg_destroy_decompress(&file);
return Containers::NullOpt;
}
/* Open file */
jpeg_create_decompress(&file);
jpeg_mem_src(&file, _in.begin(), _in.size());
/* Read file header, start decompression. On macOS (Travis, with Xcode 7.3)
the compilation fails because "no known conversion from 'bool' to
'boolean' for 2nd argument" (boolean is an enum instead of a typedef to
int there) so doing the conversion implicitly. */
jpeg_read_header(&file, boolean(true));
jpeg_start_decompress(&file);
/* Image size and type */
const Vector2i size(file.output_width, file.output_height);
static_assert(BITS_IN_JSAMPLE == 8, "Only 8-bit JPEG is supported");
/* Image format */
PixelFormat format;
switch(file.out_color_space) {
case JCS_GRAYSCALE:
CORRADE_INTERNAL_ASSERT(file.out_color_components == 1);
format = PixelFormat::R8Unorm;
break;
case JCS_RGB:
CORRADE_INTERNAL_ASSERT(file.out_color_components == 3);
format = PixelFormat::RGB8Unorm;
break;
/** @todo RGBA (only in libjpeg-turbo and probably ignored) */
default:
Error() << "Trade::JpegImporter::image2D(): unsupported color space" << file.out_color_space;
return Containers::NullOpt;
}
/* Initialize data array, align rows to four bytes */
const std::size_t stride = ((size.x()*file.out_color_components*BITS_IN_JSAMPLE/8 + 3)/4)*4;
data = Containers::Array<char>{stride*std::size_t(size.y())};
/* Read image row by row */
while(file.output_scanline < file.output_height) {
JSAMPROW row = reinterpret_cast<JSAMPROW>(data.data() + (size.y() - file.output_scanline - 1)*stride);
jpeg_read_scanlines(&file, &row, 1);
}
/* Cleanup */
jpeg_finish_decompress(&file);
jpeg_destroy_decompress(&file);
/* Always using the default 4-byte alignment */
return Trade::ImageData2D{format, size, std::move(data)};
}
开发者ID:mosra,项目名称:magnum-plugins,代码行数:75,代码来源:JpegImporter.cpp
示例10: ArrayTest
namespace Corrade { namespace Containers { namespace Test {
struct ArrayTest: TestSuite::Tester {
explicit ArrayTest();
void constructEmpty();
void constructNullptr();
void constructDefaultInit();
void constructValueInit();
void constructNoInit();
void constructDirectInit();
void construct();
void constructFromExisting();
void constructZeroSize();
void constructMove();
void constructFrom();
void constructFromChar();
void boolConversion();
void pointerConversion();
void emptyCheck();
void access();
void rvalueArrayAccess();
void rangeBasedFor();
void slice();
void sliceToStatic();
void release();
void customDeleter();
void customDeleterType();
};
typedef Containers::Array<int> Array;
ArrayTest::ArrayTest() {
addTests({&ArrayTest::constructEmpty,
&ArrayTest::constructNullptr,
&ArrayTest::constructDefaultInit,
&ArrayTest::constructValueInit,
&ArrayTest::constructNoInit,
&ArrayTest::constructDirectInit,
&ArrayTest::construct,
&ArrayTest::constructFromExisting,
&ArrayTest::constructZeroSize,
&ArrayTest::constructMove,
&ArrayTest::constructFrom,
&ArrayTest::constructFromChar,
&ArrayTest::boolConversion,
&ArrayTest::pointerConversion,
&ArrayTest::emptyCheck,
&ArrayTest::access,
&ArrayTest::rvalueArrayAccess,
&ArrayTest::rangeBasedFor,
&ArrayTest::slice,
&ArrayTest::sliceToStatic,
&ArrayTest::release,
&ArrayTest::customDeleter,
&ArrayTest::customDeleterType});
}
void ArrayTest::constructEmpty() {
const Array a;
CORRADE_VERIFY(a == nullptr);
CORRADE_COMPARE(a.size(), 0);
/* Zero-length should not call new */
const std::size_t size = 0;
const Array b(size);
CORRADE_VERIFY(b == nullptr);
CORRADE_COMPARE(b.size(), 0);
}
void ArrayTest::constructNullptr() {
const Array c(nullptr);
CORRADE_VERIFY(c == nullptr);
CORRADE_COMPARE(c.size(), 0);
/* Implicit construction from nullptr should be allowed */
CORRADE_VERIFY((std::is_convertible<std::nullptr_t, Array>::value));
}
void ArrayTest::construct() {
const Array a(5);
CORRADE_VERIFY(a != nullptr);
CORRADE_COMPARE(a.size(), 5);
/* Implicit construction from std::size_t is not allowed */
CORRADE_VERIFY(!(std::is_convertible<std::size_t, Array>::value));
}
void ArrayTest::constructFromExisting() {
int* a = new int[25];
Array b{a, 25};
CORRADE_VERIFY(b == a);
//.........这里部分代码省略.........
开发者ID:mdietsch,项目名称:corrade,代码行数:101,代码来源:ArrayTest.cpp
示例11: BufferGLTest
namespace Magnum { namespace Test {
class BufferGLTest: public AbstractOpenGLTester {
public:
explicit BufferGLTest();
void construct();
void data();
void map();
#ifdef MAGNUM_TARGET_GLES2
void mapSub();
#endif
void mapRange();
void mapRangeExplicitFlush();
#ifndef MAGNUM_TARGET_GLES2
void copy();
#endif
#ifndef MAGNUM_TARGET_GLES2
void invalidate();
#endif
};
BufferGLTest::BufferGLTest() {
addTests({&BufferGLTest::construct,
&BufferGLTest::data,
&BufferGLTest::map,
#ifdef MAGNUM_TARGET_GLES2
&BufferGLTest::mapSub,
#endif
&BufferGLTest::mapRange,
&BufferGLTest::mapRangeExplicitFlush,
#ifndef MAGNUM_TARGET_GLES2
&BufferGLTest::copy,
#endif
#ifndef MAGNUM_TARGET_GLES
&BufferGLTest::invalidate
#endif
});
}
void BufferGLTest::construct() {
Buffer buffer;
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(buffer.targetHint(), Buffer::Target::Array);
CORRADE_COMPARE(buffer.size(), 0);
MAGNUM_VERIFY_NO_ERROR();
}
void BufferGLTest::data() {
Buffer buffer;
/* Plain array */
constexpr Int data[] = {2, 7, 5, 13, 25};
buffer.setData({data, 5}, Buffer::Usage::StaticDraw);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4);
/* STL vector */
std::vector<Int> data2{2, 7, 5, 13, 25};
buffer.setData(data2, Buffer::Usage::StaticDraw);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4);
/* STL array */
std::array<Int, 5> data3{{2, 7, 5, 13, 25}};
buffer.setData(data3, Buffer::Usage::StaticDraw);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4);
/** @todo How to verify the contents in ES? */
#ifndef MAGNUM_TARGET_GLES
const Containers::Array<Int> contents = buffer.data<Int>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(contents.size(), 5);
CORRADE_COMPARE(contents[0], 2);
CORRADE_COMPARE(contents[1], 7);
CORRADE_COMPARE(contents[2], 5);
CORRADE_COMPARE(contents[3], 13);
CORRADE_COMPARE(contents[4], 25);
#endif
/* Plain array */
constexpr Int subData[] = {125, 3, 15};
buffer.setSubData(4, {subData, 3});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4);
/* STL vector */
std::vector<Int> subData2{125, 3, 15};
buffer.setSubData(4, subData2);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4);
/* STL array */
std::array<Int, 3> subData3{{125, 3, 15}};
buffer.setSubData(4, subData3);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(buffer.size(), 5*4);
//.........这里部分代码省略.........
开发者ID:awoland,项目名称:magnum,代码行数:101,代码来源:BufferGLTest.cpp
注:本文中的containers::Array类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论