本文整理汇总了C++中containers::ArrayView类的典型用法代码示例。如果您正苦于以下问题:C++ ArrayView类的具体用法?C++ ArrayView怎么用?C++ ArrayView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayView类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: write
bool Directory::write(const std::string& filename, const Containers::ArrayView<const void> data) {
std::ofstream file(filename, std::ofstream::binary);
if(!file) return false;
file.write(reinterpret_cast<const char*>(data.data()), data.size());
return true;
}
开发者ID:andylon,项目名称:corrade,代码行数:7,代码来源:Directory.cpp
示例2:
template<UnsignedInt dimensions> void BufferImage<dimensions>::setData(const PixelStorage storage, const PixelFormat format, const PixelType type, const VectorTypeFor<dimensions, Int>& size, Containers::ArrayView<const void> const data, const BufferUsage usage) {
_storage = storage;
_format = format;
_type = type;
_size = size;
/* Keep the old storage if zero-sized nullptr buffer was passed */
if(data.data() == nullptr && data.size() == 0)
CORRADE_ASSERT(Implementation::imageDataSize(*this) <= _dataSize, "BufferImage::setData(): bad current storage size, got" << _dataSize << "but expected at least" << Implementation::imageDataSize(*this), );
else {
开发者ID:Ali-Wassouf,项目名称:magnum,代码行数:10,代码来源:BufferImage.cpp
示例3: integerBase
std::pair<TweakableState, unsigned long long> TweakableParser<unsigned long long>::parse(Containers::ArrayView<const char> value) {
const std::pair<const char*, int> valueBase = integerBase(value);
char* end;
const int result = std::strtoull(valueBase.first, &end, valueBase.second);
if(end == value.begin()) {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "is not an integer literal";
return {TweakableState::Recompile, {}};
}
if(value.size() < 3 ||
(value[value.size() - 1] != 'l' && value[value.size() - 1] != 'L' &&
value[value.size() - 2] != 'l' && value[value.size() - 2] != 'L' &&
value[value.size() - 2] != 'u' && value[value.size() - 2] != 'U'))
{
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "has an unexpected suffix, expected ull";
return {TweakableState::Recompile, {}};
}
if(end != value.end() - 3) {
Warning{} << "Utility::TweakableParser: unexpected characters" << std::string{const_cast<const char*>(end), value.end()} << "after an integer literal";
return {TweakableState::Recompile, {}};
}
return {TweakableState::Success, result};
}
开发者ID:Squareys,项目名称:corrade,代码行数:26,代码来源:TweakableParser.cpp
示例4: labelImplementationKhr
void AbstractObject::labelImplementationKhr(const GLenum identifier, const GLuint name, const Containers::ArrayView<const char> label) {
#ifndef MAGNUM_TARGET_GLES
glObjectLabel(identifier, name, label.size(), label);
#elif !defined(CORRADE_TARGET_NACL)
glObjectLabelKHR(identifier, name, label.size(), label);
#else
static_cast<void>(identifier);
static_cast<void>(name);
static_cast<void>(label);
CORRADE_ASSERT_UNREACHABLE();
#endif
}
开发者ID:jaccen,项目名称:magnum,代码行数:12,代码来源:AbstractObject.cpp
示例5:
std::pair<TweakableState, char> TweakableParser<char>::parse(Containers::ArrayView<const char> value) {
if(value.size() < 3 || value.front() != '\'' || value.back() != '\'') {
Warning{} << "Utility::TweakableParser:" << std::string{value, value.size()} << "is not a character literal";
return {TweakableState::Recompile, {}};
}
if(value[1] == '\\') {
Error{} << "Utility::TweakableParser: escape sequences in char literals are not implemented, sorry";
return {TweakableState::Error, {}};
}
return {TweakableState::Success, value[1]};
}
开发者ID:Squareys,项目名称:corrade,代码行数:13,代码来源:TweakableParser.cpp
示例6: doOpenData
void JpegImporter::doOpenData(const Containers::ArrayView<const char> data) {
/* Because here we're copying the data and using the _in to check if file
is opened, having them nullptr would mean openData() would fail without
any error message. It's not possible to do this check on the importer
side, because empty file is valid in some formats (OBJ or glTF). We also
can't do the full import here because then doImage2D() would need to
copy the imported data instead anyway (and the uncompressed size is much
larger). This way it'll also work nicely with a future openMemory(). */
if(data.empty()) {
Error{} << "Trade::JpegImporter::openData(): the file is empty";
return;
}
_in = Containers::Array<unsigned char>(data.size());
std::copy(data.begin(), data.end(), _in.begin());
}
开发者ID:mosra,项目名称:magnum-plugins,代码行数:16,代码来源:JpegImporter.cpp
示例7: labelImplementationExt
void AbstractObject::labelImplementationExt(const GLenum identifier, const GLuint name, const Containers::ArrayView<const char> label) {
#ifndef CORRADE_TARGET_NACL
const GLenum type = extTypeFromKhrIdentifier(identifier);
glLabelObjectEXT(type, name, label.size(), label);
#else
static_cast<void>(identifier);
static_cast<void>(name);
static_cast<void>(label);
CORRADE_ASSERT_UNREACHABLE();
#endif
}
开发者ID:jaccen,项目名称:magnum,代码行数:11,代码来源:AbstractObject.cpp
示例8: doOpenData
void StbVorbisImporter::doOpenData(Containers::ArrayView<const char> data) {
Int numChannels, frequency;
Short* decodedData = nullptr;
Int samples = stb_vorbis_decode_memory(reinterpret_cast<const UnsignedByte*>(data.data()), data.size(), &numChannels, &frequency, &decodedData);
if(samples == -1) {
Error() << "Audio::StbVorbisImporter::openData(): the file signature is invalid";
return;
} else if (samples == -2) {
/* memory allocation failure */
Error() << "Audio::StbVorbisImporter::openData(): out of memory";
return;
}
Containers::Array<char> tempData{reinterpret_cast<char*>(decodedData), size_t(samples*numChannels*2),
[](char* data, size_t) { std::free(data); }};
_frequency = frequency;
/* Decide about format */
if(numChannels == 1)
_format = Buffer::Format::Mono16;
else if(numChannels == 2)
_format = Buffer::Format::Stereo16;
/** @todo Buffer::Format::*Float32 when extension support is done */
else {
Error() << "Audio::StbVorbisImporter::openData(): unsupported channel count"
<< numChannels << "with" << 16 << "bits per sample";
return;
}
_data = std::move(tempData);
return;
}
开发者ID:Squareys,项目名称:magnum-plugins,代码行数:36,代码来源:StbVorbisImporter.cpp
示例9: equalsPrefix
inline bool equalsPrefix(const Containers::ArrayView<const char> data, const char* const prefix) {
return std::strncmp(data, prefix, data.size()) == 0;
}
开发者ID:mosra,项目名称:magnum-plugins,代码行数:3,代码来源:Parsers.cpp
示例10: doOpenData
void JpegImporter::doOpenData(const Containers::ArrayView<const char> data) {
_in = Containers::Array<unsigned char>(data.size());
std::copy(data.begin(), data.end(), _in.begin());
}
开发者ID:caomw,项目名称:magnum-plugins,代码行数:4,代码来源:JpegImporter.cpp
示例11: uniformLocationInternal
Int AbstractShaderProgram::uniformLocationInternal(const Containers::ArrayView<const char> name) {
GLint location = glGetUniformLocation(_id, name);
if(location == -1)
Warning() << "AbstractShaderProgram: location of uniform \'" + std::string{name, name.size()} + "\' cannot be retrieved!";
return location;
}
开发者ID:shaobozi,项目名称:magnum,代码行数:6,代码来源:AbstractShaderProgram.cpp
示例12: setUniform
void AbstractShaderProgram::setUniform(const Int location, const Containers::ArrayView<const Math::Vector<4, UnsignedInt>> values) {
(this->*Context::current()->state().shaderProgram->uniform4uivImplementation)(location, values.size(), values);
}
开发者ID:shaobozi,项目名称:magnum,代码行数:3,代码来源:AbstractShaderProgram.cpp
示例13: doOpenData
void AnyImageImporter::doOpenData(Containers::ArrayView<const char> data) {
CORRADE_INTERNAL_ASSERT(manager());
std::string plugin;
/* https://docs.microsoft.com/cs-cz/windows/desktop/direct3ddds/dx-graphics-dds-pguide */
if(Utility::String::viewBeginsWith(data, "DDS "))
plugin = "DdsImporter";
/* http://www.openexr.com/openexrfilelayout.pdf */
else if(Utility::String::viewBeginsWith(data, "\x76\x2f\x31\x01"))
plugin = "OpenExrImporter";
/* https://en.wikipedia.org/wiki/Radiance_(software)#HDR_image_format */
else if(Utility::String::viewBeginsWith(data, "#?RADIANCE"))
plugin = "HdrImporter";
/* https://en.wikipedia.org/wiki/JPEG#Syntax_and_structure */
else if(Utility::String::viewBeginsWith(data, "\xff\xd8\xff"))
plugin = "JpegImporter";
/* https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header */
else if(Utility::String::viewBeginsWith(data, "\x89PNG\x0d\x0a\x1a\x0a"))
plugin = "PngImporter";
/* https://github.com/file/file/blob/d04de269e0b06ccd0a7d1bf4974fed1d75be7d9e/magic/Magdir/images#L18-L22
TGAs are a complete guesswork, so try after everything else fails. */
else if([data]() {
/* TGA header is 18 bytes */
if(data.size() < 18) return false;
/* Third byte (image type) must be one of these */
if(data[2] != 1 && data[2] != 2 && data[2] != 3 &&
data[2] != 9 && data[2] != 10 && data[2] != 11) return false;
/* If image type is 1 or 9, second byte (colormap type) must be 1 */
if((data[2] == 1 || data[2] == 9) && data[1] != 1) return false;
/* ... and 0 otherwise */
if(data[2] != 1 && data[2] != 9 && data[1] != 0) return false;
/* Colormap index (unsigned short, byte 3+4) should be 0 */
if(data[3] != 0 && data[4] != 0) return false;
/* Probably TGA, heh. Or random memory. */
return true;
}()) plugin = "TgaImporter";
else if(!data.size()) {
Error{} << "Trade::AnyImageImporter::openData(): file is empty";
return;
} else {
std::uint32_t signature = data[0] << 24;
if(data.size() > 1) signature |= data[1] << 16;
if(data.size() > 2) signature |= data[2] << 8;
if(data.size() > 3) signature |= data[3];
Error() << "Trade::AnyImageImporter::openData(): cannot determine type from signature" << reinterpret_cast<void*>(signature);
return;
}
/* Try to load the plugin */
if(!(manager()->load(plugin) & PluginManager::LoadState::Loaded)) {
Error() << "Trade::AnyImageImporter::openData(): cannot load" << plugin << "plugin";
return;
}
/* Try to open the file (error output should be printed by the plugin
itself) */
Containers::Pointer<AbstractImporter> importer = static_cast<PluginManager::Manager<AbstractImporter>*>(manager())->instantiate(plugin);
if(!importer->openData(data)) return;
/* Success, save the instance */
_in = std::move(importer);
}
开发者ID:Squareys,项目名称:magnum,代码行数:67,代码来源:AnyImageImporter.cpp
示例14: doOpenData
void DrWavImporter::doOpenData(const Containers::ArrayView<const char> data) {
drwav* const handle = drwav_open_memory(data.data(), data.size());
if(!handle) {
Error() << "Audio::DrWavImporter::openData(): failed to open and decode WAV data";
return;
}
Containers::ScopeGuard drwavClose{handle, drwav_close};
const std::uint64_t samples = handle->totalSampleCount;
const std::uint32_t frequency = handle->sampleRate;
const std::uint8_t numChannels = handle->channels;
const std::uint8_t bitsPerSample = handle->bitsPerSample;
/* If the bits per sample is exact, we can read data raw */
const Int notExactBitsPerSample = ((bitsPerSample % 8) ? 1 : 0);
/* Normalize bit amounts to multiples of 8, rounding up */
const UnsignedInt normalizedBytesPerSample = (bitsPerSample / 8) + notExactBitsPerSample;
if(numChannels == 0 || numChannels == 3 || numChannels == 5 || numChannels > 8 ||
normalizedBytesPerSample == 0 || normalizedBytesPerSample > 8) {
Error() << "Audio::DrWavImporter::openData(): unsupported channel count"
<< numChannels << "with" << bitsPerSample
<< "bits per sample";
return;
}
/* Can't load something with no samples */
if(samples == 0) {
Error() << "Audio::DrWavImporter::openData(): no samples";
return;
}
_frequency = frequency;
/* PCM has a lot of special cases, as we can read many formats directly */
if(handle->translatedFormatTag == DR_WAVE_FORMAT_PCM) {
_format = PcmFormatTable[numChannels-1][normalizedBytesPerSample-1];
CORRADE_INTERNAL_ASSERT(_format != BufferFormat{});
/* If the data is exactly 8 or 16 bits, we can read it raw */
if(!notExactBitsPerSample && normalizedBytesPerSample < 3) {
_data = readRaw(handle, samples, normalizedBytesPerSample);
return;
/* If the data is approximately 24 bits or has many channels, a float is more than enough */
} else if(normalizedBytesPerSample == 3 || (normalizedBytesPerSample > 3 && numChannels > 3)) {
_data = read32fPcm(handle, samples, numChannels, _format);
return;
/* If the data is close to 8 or 16 bits, we can convert it from 32-bit PCM */
} else if(normalizedBytesPerSample == 1 || normalizedBytesPerSample == 2) {
Containers::Array<char> tempData(samples*sizeof(Int));
drwav_read_s32(handle, samples, reinterpret_cast<Int*>(tempData.begin()));
/* 32-bit PCM can be sliced down to 8 or 16 for direct reading */
_data = convert32Pcm(tempData, samples, normalizedBytesPerSample);
/* Convert 8 bit data to unsigned */
if(normalizedBytesPerSample == 1)
for(char& item: _data) item = item - 128;
return;
}
/** @todo Allow loading of 32/64 bit streams to Double format to preserve all information */
/* ALaw of 8/16 bits with 1/2 channels can be loaded directly */
} else if(handle->translatedFormatTag == DR_WAVE_FORMAT_ALAW) {
if(numChannels < 3 && !notExactBitsPerSample && (bitsPerSample == 8 || bitsPerSample == 16) ) {
_format = ALawFormatTable[numChannels-1][normalizedBytesPerSample-1];
_data = readRaw(handle, samples, normalizedBytesPerSample);
return;
}
/* MuLaw of 8/16 bits with 1/2 channels can be loaded directly */
} else if(handle->translatedFormatTag == DR_WAVE_FORMAT_MULAW) {
if(numChannels < 3 && !notExactBitsPerSample && (bitsPerSample == 8 || bitsPerSample == 16) ) {
_format = MuLawFormatTable[numChannels-1][normalizedBytesPerSample-1];
_data = readRaw(handle, samples, normalizedBytesPerSample);
return;
}
/* IEEE float or double can be loaded directly */
} else if(handle->translatedFormatTag == DR_WAVE_FORMAT_IEEE_FLOAT) {
if(!notExactBitsPerSample && (bitsPerSample == 32 || bitsPerSample == 64)) {
_format = IeeeFormatTable[numChannels-1][(normalizedBytesPerSample / 4)-1];
_data = readRaw(handle, samples, normalizedBytesPerSample);
return;
}
}
/* If we don't know what the format is, read it out as 32 bit float for compatibility */
_data = read32fPcm(handle, samples, numChannels, _format);
return;
}
开发者ID:mosra,项目名称:magnum-plugins,代码行数:95,代码来源:DrWavImporter.cpp
示例15: doOpenData
void DrFlacImporter::doOpenData(Containers::ArrayView<const char> data) {
drflac* const handle = drflac_open_memory(data.data(), data.size());
if(!handle) {
Error() << "Audio::DrFlacImporter::openData(): failed to open and decode FLAC data";
return;
}
Containers::ScopeGuard drflacClose{handle, drflac_close};
const std::uint64_t samples = handle->totalSampleCount;
const std::uint8_t numChannels = handle->channels;
const std::uint8_t bitsPerSample = handle->bitsPerSample;
/* FLAC supports any bitspersample from 4 to 64, but DrFlac always gives us
32-bit samples. So we normalize bit amounts to multiples of 8, rounding
up. */
const UnsignedInt normalizedBytesPerSample = (bitsPerSample + 7)/8;
if(numChannels == 0 || numChannels == 3 || numChannels == 5 || numChannels > 8 ||
normalizedBytesPerSample == 0 || normalizedBytesPerSample > 8) {
Error() << "Audio::DrFlacImporter::openData(): unsupported channel count"
<< numChannels << "with" << bitsPerSample
<< "bits per sample";
return;
}
/* Can't load something with no samples */
if(samples == 0) {
Error() << "Audio::DrFlacImporter::openData(): no samples";
return;
}
_frequency = handle->sampleRate;
_format = flacFormatTable[numChannels-1][normalizedBytesPerSample-1];
CORRADE_INTERNAL_ASSERT(_format != BufferFormat{});
/* 32-bit integers need to be normalized to Double (with a 32 bit mantissa) */
if(normalizedBytesPerSample == 4) {
Containers::Array<Int> tempData(samples);
drflac_read_s32(handle, samples, reinterpret_cast<Int*>(tempData.begin()));
/* If the channel is mono/stereo, we can use double samples */
if(numChannels < 3) {
Containers::Array<Double> doubleData(samples);
for(std::size_t i = 0; i < samples; ++i) {
doubleData[i] = Math::unpack<Double>(tempData[i]);
}
const char* doubleBegin = reinterpret_cast<const char*>(doubleData.begin());
const char* doubleEnd = reinterpret_cast<const char*>(doubleData.end());
_data = Containers::Array<char>(samples*sizeof(Double));
std::copy(doubleBegin, doubleEnd, _data.begin());
/* Otherwise, convert to float */
} else {
Containers::Array<Float> floatData(samples);
for(std::size_t i = 0; i < samples; ++i) {
floatData[i] = Math::unpack<Float>(tempData[i]);
}
const char* floatBegin = reinterpret_cast<const char*>(floatData.begin());
const char* floatEnd = reinterpret_cast<const char*>(floatData.end());
_data = Containers::Array<char>(samples*sizeof(Float));
std::copy(floatBegin, floatEnd, _data.begin());
}
return;
}
Containers::Array<char> tempData(samples*sizeof(Int));
drflac_read_s32(handle, samples, reinterpret_cast<Int*>(tempData.begin()));
_data = convert32PCM(tempData, samples, normalizedBytesPerSample);
/* 8-bit needs to become unsigned */
if(normalizedBytesPerSample == 1) {
for(char& item: _data) item = item - 128;
/* 24-bit needs to become float */
} else if(normalizedBytesPerSample == 3) {
Containers::Array<Float> floatData(samples);
for(std::size_t i = 0; i != samples; ++i) {
const UnsignedInt s0 = _data[i*3 + 0];
const UnsignedInt s1 = _data[i*3 + 1];
const UnsignedInt s2 = _data[i*3 + 2];
const Int intData = Int((s0 << 8) | (s1 << 16) | (s2 << 24));
floatData[i] = Math::unpack<Float>(intData);
}
const char* const floatBegin = reinterpret_cast<const char*>(floatData.begin());
const char* const floatEnd = reinterpret_cast<const char*>(floatData.end());
_data = Containers::Array<char>(samples*sizeof(Float));
std::copy(floatBegin, floatEnd, _data.begin());
}
//.........这里部分代码省略.........
开发者ID:mosra,项目名称:magnum-plugins,代码行数:101,代码来源:DrFlacImporter.cpp
示例16: doOpenData
void TgaImporter::doOpenData(const Containers::ArrayView<const char> data) {
_in = Containers::Array<char>{data.size()};
std::copy(data.begin(), data.end(), _in.begin());
}
开发者ID:jkhoogland,项目名称:magnum,代码行数:4,代码来源:TgaImporter.cpp
示例17: get
std::string Resource::get(const std::string& filename) const {
Containers::ArrayView<const char> data = getRaw(filename);
return data ? std::string{data, data.size()} : std::string{};
}
开发者ID:Gerharddc,项目名称:corrade,代码行数:4,代码来源:Resource.cpp
示例18: doOpenData
void WavImporter::doOpenData(Containers::ArrayView<const char> data) {
/* Check file size */
if(data.size() < sizeof(WavHeader)) {
Error() << "Audio::WavImporter::openData(): the file is too short:" << data.size() << "bytes";
return;
}
/* Get header contents and fix endianness */
WavHeader header(*reinterpret_cast<const WavHeader*>(data.begin()));
Utility::Endianness::littleEndianInPlace(header.chunkSize,
header.subChunk1Size, header.audioFormat, header.numChannels,
header.sampleRate, header.byteRate, header.blockAlign,
header.bitsPerSample, header.subChunk2Size);
/* Check file signature */
if(std::strncmp(header.chunkId, "RIFF", 4) != 0 ||
std::strncmp(header.format, "WAVE", 4) != 0 ||
std::strncmp(header.subChunk1Id, "fmt ", 4) != 0 ||
std::strncmp(header.subChunk2Id, "data", 4) != 0) {
Error() << "Audio::WavImporter::openData(): the file signature is invalid";
return;
}
/* Check file size */
if(header.chunkSize + 8 != data.size()) {
Error() << "Audio::WavImporter::openData(): the file has improper size, expected"
<< header.chunkSize + 8 << "but got" << data.size();
return;
}
/* Check PCM format */
if(header.audioFormat != 1) {
Error() << "Audio::WavImporter::openData(): unsupported audio format" << header.audioFormat;
return;
}
/* Verify more things */
if(header.subChunk1Size != 16 ||
header.subChunk2Size + 44 != data.size() ||
header.blockAlign != header.numChannels*header.bitsPerSample/8 ||
header.byteRate != header.sampleRate*header.blockAlign) {
Error() << "Audio::WavImporter::openData(): the file is corrupted";
return;
}
/* Decide about format */
if(header.numChannels == 1 && header.bitsPerSample == 8)
_format = Buffer::Format::Mono8;
else if(header.numChannels == 1 && header.bitsPerSample == 16)
_format = Buffer::Format::Mono16;
else if(header.numChannels == 2 && header.bitsPerSample == 8)
_format = Buffer::Format::Stereo8;
else if(header.numChannels == 2 && header.bitsPerSample == 16)
_format = Buffer::Format::Stereo16;
else {
Error() << "Audio::WavImporter::openData(): unsupported channel count"
<< header.numChannels << "with" << header.bitsPerSample
<< "bits per sample";
return;
}
/* Save frequency */
_frequency = header.sampleRate;
/** @todo Convert the data from little endian too */
CORRADE_INTERNAL_ASSERT(!Utility::Endianness::isBigEndian());
/* Copy the data */
_data = Containers::Array<char>(header.subChunk2Size);
std::copy(data.begin()+sizeof(WavHeader), data.end(), _data.begin());
return;
}
开发者ID:BrainlessLabsInc,项目名称:magnum,代码行数:72,代码来源:WavImporter.cpp
注:本文中的containers::ArrayView类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论