本文整理汇总了C++中std::vector::data方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::data方法的具体用法?C++ vector::data怎么用?C++ vector::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::vector
的用法示例。
在下文中一共展示了vector::data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: destroyVulkan
//==============================================================================
// Vulkan破棄
//==============================================================================
void destroyVulkan()
{
for(auto& frameBuffer : g_frameBuffers)
{
vkDestroyFramebuffer(g_VulkanDevice, frameBuffer, nullptr);
}
if(g_depthBufferTexture.view)
{
vkDestroyImageView(g_VulkanDevice, g_depthBufferTexture.view, nullptr);
}
if(g_depthBufferTexture.image)
{
vkDestroyImage(g_VulkanDevice, g_depthBufferTexture.image, nullptr);
}
if(g_depthBufferTexture.memory)
{
vkFreeMemory(g_VulkanDevice, g_depthBufferTexture.memory, nullptr);
}
if(g_commandBuffers.empty() == false)
{
vkFreeCommandBuffers(g_VulkanDevice, g_VulkanCommandPool, SWAP_CHAIN_COUNT, g_commandBuffers.data());
}
if(g_VulkanCommandPool)
{
vkDestroyCommandPool(g_VulkanDevice, g_VulkanCommandPool, nullptr);
}
if(g_VulkanSemahoreRenderComplete)
{
vkDestroySemaphore(g_VulkanDevice, g_VulkanSemahoreRenderComplete, nullptr);
}
if(g_VulkanFence)
{
vkDestroyFence(g_VulkanDevice, g_VulkanFence, nullptr);
}
if(g_VulkanSwapChain)
{
vkDestroySwapchainKHR(g_VulkanDevice, g_VulkanSwapChain, nullptr);
}
if(g_VulkanSurface)
{
vkDestroySurfaceKHR(g_VulkanInstance, g_VulkanSurface, nullptr);
}
if(g_VulkanDevice)
{
vkDestroyDevice(g_VulkanDevice, nullptr);
}
if(g_VulkanInstance)
{
vkDestroyInstance(g_VulkanInstance, nullptr);
}
g_frameBuffers.clear();
g_commandBuffers.clear();
g_VulkanSurface = nullptr;
g_VulkanSwapChain = nullptr;
g_VulkanCommandPool = nullptr;
g_VulkanSemahoreRenderComplete = nullptr;
g_VulkanFence = nullptr;
g_VulkanQueue = nullptr;
g_VulkanDevice = nullptr;
g_VulkanInstance = nullptr;
}
示例2: ParseEndpointsFromWSD
/// <summary>
/// Parses information about endpoints from a WSDL document.
/// </summary>
/// <param name="wsdContent">Web service definition content previously loaded from a file.</param>
/// <param name="bindings">The bindings assigned to the endpoints.</param>
/// <param name="targetNamespace">Where to save the target namespace.</param>
/// <param name="serviceName">Where to save the service name.</param>
/// <param name="endpointsAddrs">Where to save the addresses of the endpoints.</param>
/// <remarks>
/// Assumes the usage of HTTP & SOAP, but does not check if the document is thoroughly
/// well formed. Because this library is meant to integrate with wsutil.exe generated code,
/// the WSDL document is expected to follow the specification in http://www.w3.org/TR/wsdl.
/// Also, the bindings MUST BE declared in the target namespace using the prefix 'tns'.
/// </remarks>
static void ParseEndpointsFromWSD(
const std::vector<char> &wsdContent,
const ServiceBindings &bindings,
string &targetNamespace,
string &serviceName,
std::vector<SvcEndpointInfo> &endpointsInfo)
{
using namespace Poco;
CALL_STACK_TRACE;
try
{
// If anything goes wrong, do not keep any previous content in the output:
targetNamespace.clear();
serviceName.clear();
endpointsInfo.clear();
// Fundamental namespaces URI's:
static const string wsdlNs("http://schemas.xmlsoap.org/wsdl/"),
soapNs("http://schemas.xmlsoap.org/wsdl/soap/");
XML::NamespaceSupport nsmap;
nsmap.declarePrefix("wsdl", wsdlNs);
nsmap.declarePrefix("soap", soapNs);
// Parse XML from memory:
XML::DOMParser parser;
parser.setFeature(XML::SAXParser::FEATURE_NAMESPACE_PREFIXES, true);
parser.setFeature(XML::SAXParser::FEATURE_NAMESPACES, true);
AutoPtr<XML::Document> document = parser.parseMemory(wsdContent.data(), wsdContent.size());
// Get /wsdl:definitions
auto definitions = static_cast<XML::Element *> (
document->getNodeByPathNS("/wsdl:definitions", nsmap)
);
if (definitions == nullptr)
{
throw AppException<std::runtime_error>(
"Web service definition is not compliant",
"The WSDL definitions element is missing"
);
}
// Get /wsdl:definitions[@targetNamespace]
auto attr = definitions->getAttributeNode("targetNamespace");
if (attr != nullptr)
{
targetNamespace = attr->nodeValue();
nsmap.declarePrefix("tns", targetNamespace);
}
else
{
throw AppException<std::runtime_error>(
"Web service definition is not compliant",
"The target namespace is missing from WSDL document"
);
}
// Get /wsdl:definitions/wsdl:service
auto svcElement = definitions->getChildElementNS(wsdlNs, "service");
if (svcElement == nullptr)
{
throw AppException<std::runtime_error>(
"Web service definition is not compliant",
"The WSDL service element is missing from document"
);
}
// Get /wsdl:definitions/wsdl:service[@name]
attr = svcElement->getAttributeNode("name");
if (attr != nullptr)
serviceName = attr->nodeValue();
else
{
throw AppException<std::runtime_error>(
"Web service definition is not compliant",
"The attribute \'name\' was missing from the WSDL service element"
);
}
// Get the /wsdl:definitions/wsdl:service/wsdl:port' elements:
AutoPtr<XML::NodeList> portNodes = svcElement->getElementsByTagNameNS(wsdlNs, "port");
if (portNodes->length() == 0)
//.........这里部分代码省略.........
示例3: microfacetFourierSeries
void microfacetFourierSeries(Float mu_o, Float mu_i, std::complex<Float> eta_,
Float alpha, size_t n, Float relerr,
std::vector<Float> &result) {
bool reflect = -mu_i * mu_o > 0;
/* Compute the 'A' and 'B' constants, as well as the critical azimuth */
Float A, B;
Float sinMu2 = math::safe_sqrt((1 - mu_i * mu_i) * (1 - mu_o * mu_o));
bool conductor = (eta_.imag() != 0.0f);
std::complex<Float> eta =
(-mu_i > 0 || conductor) ? eta_ : std::complex<Float>(1) / eta_;
if (reflect) {
Float temp = 1.0f / (alpha * (mu_i - mu_o));
A = (mu_i * mu_i + mu_o * mu_o - 2) * temp * temp;
B = 2 * sinMu2 * temp * temp;
} else {
if (conductor) {
/* No refraction in conductors */
result.clear();
result.push_back(0.0f);
return;
} else {
Float temp = 1.0f / (alpha * (mu_i - eta.real() * mu_o));
A = (mu_i * mu_i - 1 + eta.real() * eta.real() * (mu_o * mu_o - 1)) * temp * temp;
B = 2 * eta.real() * sinMu2 * temp * temp;
}
}
/* Minor optimization: don't even bother computing the Fourier series
if the contribution to the scattering model is miniscule */
if (math::i0e(B) * std::exp(A+B) < 1e-10) {
result.clear();
result.push_back(0.0f);
return;
}
Float B_max = Bmax(n, relerr);
if (B > B_max) {
A = A + B - B_max + std::log(math::i0e(B) / math::i0e(B_max));
B = B_max;
}
std::vector<Float> lowfreq_coeffs, expcos_coeffs;
/* Compute Fourier coefficients of the exponential term */
expCosFourierSeries(A, B, relerr, expcos_coeffs);
/* Compute Fourier coefficients of the low-frequency term
Only fit in the region where the result is actually
going to make some sort of difference given the convolution
with expcos_coeffs */
Float phiMax = math::safe_acos(1 + std::log(relerr) / B);
microfacetNoExpFourierSeries(mu_o, mu_i, eta_, alpha,
12, phiMax, lowfreq_coeffs);
/* Perform discrete circular convolution of the two series */
result.resize(lowfreq_coeffs.size() + expcos_coeffs.size() - 1);
convolveFourier(lowfreq_coeffs.data(), lowfreq_coeffs.size(),
expcos_coeffs.data(), expcos_coeffs.size(), result.data());
/* Truncate the series if error bounds are satisfied */
for (size_t i=0; i<result.size(); ++i) {
assert(std::isfinite(result[i]));
if (result[i] == 0 || std::abs(result[i]) < result[0] * relerr) {
result.erase(result.begin() + i, result.end());
break;
}
}
}
示例4: decode
void PNGCodec::decode(std::vector<uint8_t> &in,
std::vector<uint8_t> *out, unsigned int *width,
unsigned int *height, ColorFormat *format, uint8_t level)
{
if (level != 0)
{
// TODO: Error handling.
return;
}
if (png_check_sig(in.data(), SIGNATURE_LENGTH) == false)
{
// TODO: Error handling.
return;
}
png_structp pngPtr = png_create_read_struct(
PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (pngPtr == nullptr)
{
// TODO: Error handling.
return;
}
png_infop pngInfoPtr = png_create_info_struct(pngPtr);
if (pngInfoPtr == nullptr)
{
// TODO: Error handling.
png_destroy_read_struct(&pngPtr, nullptr, nullptr);
return;
}
PNGVectorStream stream;
stream.vec = ∈
stream.offset = 0;
png_set_read_fn(pngPtr, &stream, PNGReadCallback);
png_read_info(pngPtr, pngInfoPtr);
int bitDepth = 0;
int colorType = -1;
png_uint_32 retval = png_get_IHDR(pngPtr, pngInfoPtr,
width,
height,
&bitDepth,
&colorType,
nullptr, nullptr, nullptr);
if (retval != 1)
{
// TODO: Error handling.
png_destroy_read_struct(&pngPtr, &pngInfoPtr, nullptr);
return;
}
switch (colorType)
{
case PNG_COLOR_TYPE_RGB:
*format = ColorFormat::RGB;
break;
case PNG_COLOR_TYPE_RGBA:
*format = ColorFormat::RGBA;
break;
default:
// TODO: Error handling.
png_destroy_read_struct(&pngPtr, &pngInfoPtr, nullptr);
return;
}
out->resize((*width) * (*height) * static_cast<unsigned int>(*format));
for (unsigned int i = 0; i < *height; ++i)
png_read_row(pngPtr,
&(*out)[i * (*width) * static_cast<unsigned int>(*format)], nullptr);
png_destroy_read_struct(&pngPtr, &pngInfoPtr, nullptr);
}
示例5: parseTransactionExtra
bool parseTransactionExtra(const std::vector<uint8_t> &transactionExtra, std::vector<TransactionExtraField> &transactionExtraFields) {
transactionExtraFields.clear();
if (transactionExtra.empty())
return true;
try {
MemoryInputStream iss(transactionExtra.data(), transactionExtra.size());
BinaryInputStreamSerializer ar(iss);
int c = 0;
while (!iss.endOfStream()) {
c = read<uint8_t>(iss);
switch (c) {
case TX_EXTRA_TAG_PADDING: {
size_t size = 1;
for (; !iss.endOfStream() && size <= TX_EXTRA_PADDING_MAX_COUNT; ++size) {
if (read<uint8_t>(iss) != 0) {
return false; // all bytes should be zero
}
}
if (size > TX_EXTRA_PADDING_MAX_COUNT) {
return false;
}
transactionExtraFields.push_back(TransactionExtraPadding{ size });
break;
}
case TX_EXTRA_TAG_PUBKEY: {
TransactionExtraPublicKey extraPk;
ar(extraPk.publicKey, "public_key");
transactionExtraFields.push_back(extraPk);
break;
}
case TX_EXTRA_NONCE: {
TransactionExtraNonce extraNonce;
uint8_t size = read<uint8_t>(iss);
if (size > 0) {
extraNonce.nonce.resize(size);
read(iss, extraNonce.nonce.data(), extraNonce.nonce.size());
}
transactionExtraFields.push_back(extraNonce);
break;
}
case TX_EXTRA_MERGE_MINING_TAG: {
TransactionExtraMergeMiningTag mmTag;
ar(mmTag, "mm_tag");
transactionExtraFields.push_back(mmTag);
break;
}
case TX_EXTRA_MESSAGE_TAG: {
tx_extra_message message;
ar(message.data, "message");
transactionExtraFields.push_back(message);
break;
}
case TX_EXTRA_TTL: {
uint8_t size;
readVarint(iss, size);
TransactionExtraTTL ttl;
readVarint(iss, ttl.ttl);
transactionExtraFields.push_back(ttl);
break;
}
}
}
} catch (std::exception &) {
return false;
}
return true;
}
示例6: hash_bytes
std::vector<byte> hash_bytes(const std::vector<byte, A>& v)
{
return hash_bytes(v.data(), v.size());
}
示例7: render
void CustomPostEffectShader::render(Camera* camera,
RenderTexture* render_texture,
PostEffectData* post_effect_data,
std::vector<glm::vec3>& vertices, std::vector<glm::vec2>& tex_coords,
std::vector<unsigned short>& triangles) {
glUseProgram(program_->id());
#if _GVRF_USE_GLES3_
GLuint tmpID;
if(vaoID_ == 0)
{
glGenVertexArrays(1, &vaoID_);
glBindVertexArray(vaoID_);
glGenBuffers(1, &tmpID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tmpID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short)*triangles.size(), &triangles[0], GL_STATIC_DRAW);
if (vertices.size())
{
glGenBuffers(1, &tmpID);
glBindBuffer(GL_ARRAY_BUFFER, tmpID);
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3)*vertices.size(), &vertices[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(a_position_);
glVertexAttribPointer(a_position_, 3, GL_FLOAT, 0, 0, 0);
}
if (tex_coords.size())
{
glGenBuffers(1, &tmpID);
glBindBuffer(GL_ARRAY_BUFFER, tmpID);
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec2)*tex_coords.size(), &tex_coords[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(a_tex_coord_);
glVertexAttribPointer(a_tex_coord_, 2, GL_FLOAT, 0, 0, 0);
}
}
int texture_index = 0;
if (u_texture_ != -1) {
glActiveTexture(getGLTexture(texture_index));
glBindTexture(GL_TEXTURE_2D, render_texture->getId());
glUniform1i(u_texture_, texture_index++);
}
if (u_projection_matrix_ != -1) {
glm::mat4 view = camera->getViewMatrix();
glUniformMatrix4fv(u_projection_matrix_, 1, GL_TRUE, glm::value_ptr(view));
}
if (u_right_eye_ != -1) {
bool right = camera->render_mask() & RenderData::RenderMaskBit::Right;
glUniform1i(u_right_eye_, right ? 1 : 0);
}
for (auto it = texture_keys_.begin(); it != texture_keys_.end(); ++it) {
glActiveTexture(getGLTexture(texture_index));
Texture* texture = post_effect_data->getTexture(it->second);
glBindTexture(texture->getTarget(), texture->getId());
glUniform1i(it->first, texture_index++);
}
for (auto it = float_keys_.begin(); it != float_keys_.end(); ++it) {
glUniform1f(it->first, post_effect_data->getFloat(it->second));
}
for (auto it = vec2_keys_.begin(); it != vec2_keys_.end(); ++it) {
glm::vec2 v = post_effect_data->getVec2(it->second);
glUniform2f(it->first, v.x, v.y);
}
for (auto it = vec3_keys_.begin(); it != vec3_keys_.end(); ++it) {
glm::vec3 v = post_effect_data->getVec3(it->second);
glUniform3f(it->first, v.x, v.y, v.z);
}
for (auto it = vec4_keys_.begin(); it != vec4_keys_.end(); ++it) {
glm::vec4 v = post_effect_data->getVec4(it->second);
glUniform4f(it->first, v.x, v.y, v.z, v.w);
}
for (auto it = mat4_keys_.begin(); it != mat4_keys_.end(); ++it) {
glm::mat4 m = post_effect_data->getMat4(it->second);
glUniformMatrix4fv(it->first, 1, GL_FALSE, glm::value_ptr(m));
}
glBindVertexArray(vaoID_);
glDrawElements(GL_TRIANGLES, triangles.size(), GL_UNSIGNED_SHORT, 0);
glBindVertexArray(0);
#else
if (a_position_ != -1) {
glVertexAttribPointer(a_position_, 3, GL_FLOAT, GL_FALSE, 0,
vertices.data());
glEnableVertexAttribArray(a_position_);
}
if (a_tex_coord_ != -1) {
glVertexAttribPointer(a_tex_coord_, 2, GL_FLOAT, GL_FALSE, 0,
//.........这里部分代码省略.........
示例8: assert
base_blob<BITS>::base_blob(const std::vector<unsigned char>& vch)
{
assert(vch.size() == sizeof(data));
memcpy(data, vch.data(), sizeof(data));
}
示例9: AbstractFile
MemoryBuffer::MemoryBuffer(std::vector<unsigned char>& data) :
AbstractFile(data.size()),
buffer_(data.data()),
readOnly_(false)
{
}
示例10:
std::string EncodeBase58(const std::vector<unsigned char>& vch)
{
return EncodeBase58(vch.data(), vch.data() + vch.size());
}
示例11: main
int main(int argc,char **argv)
{
using std::cout;
using std::endl;
std::string output;
int L = 0;
int N = 0;
double U = 0;
bool momspace = false;
struct option long_options[] =
{
{"output", required_argument, 0, 'o'},
{"interaction", required_argument, 0, 'U'},
{"sites", required_argument, 0, 'L'},
{"particles", required_argument, 0, 'N'},
{"momspace", no_argument, 0, 'm'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
int i,j;
while( (j = getopt_long (argc, argv, "ho:U:L:N:m", long_options, &i)) != -1)
switch(j)
{
case 'h':
case '?':
cout << "Usage: " << argv[0] << " [OPTIONS]\n"
"\n"
" -o, --output=output-filename Set the output filename\n"
" -L, --sites=L Set the number of sites\n"
" -N, --particles=N Set the number of particles\n"
" -U, --interaction=U Set the on-site interaction\n"
" -m, --momspace Work in momentum space\n"
" -h, --help Display this help\n"
"\n";
return 0;
break;
case 'o':
output = optarg;
break;
case 'U':
U = atof(optarg);
break;
case 'L':
L = atoi(optarg);
break;
case 'N':
N = atoi(optarg);
break;
case 'm':
momspace = true;
break;
}
if(! (L && N))
{
std::cerr << "You need to specifiy the system!" << endl;
return 1;
}
cout << "Creating for L= " << L << " N= " << N << " U= " << U << endl;
const std::vector<int> orb2irrep (L, 0);
CheMPS2::Hamiltonian ham(L, 0, orb2irrep.data());
// put everything to zero
ham.reset();
ham.setNe(N);
ham.setEconst(0);
if(momspace)
{
// Don't forget: you cannot rotate states of different momentum!
// one-particle integrals
for(int i=0;i<L;i++)
ham.setTmat(i, i, -2*std::cos(2*M_PI/(1.0*L)*i));
// two-particle integrals
for(int k1=0;k1<L;k1++)
for(int k2=0;k2<L;k2++)
for(int k3=0;k3<L;k3++)
for(int k4=0;k4<L;k4++)
if((k1+k2)%L == (k3+k4)%L)
ham.setVmat(k1,k2,k3,k4, U*1.0/L);
} else
{
// one-particle integrals
for(int i=1;i<(L-1);i++)
{
ham.setTmat(i, i+1, -1);
ham.setTmat(i, i-1, -1);
}
ham.setTmat(0, 1, -1);
ham.setTmat(L-1, L-2, -1);
//.........这里部分代码省略.........
示例12: write
int Socket::write(const std::vector<char> &data){
return this->write((void*) data.data(), data.size());
}
示例13: read
void read(IInputStream& in, std::vector<uint8_t>& data, size_t size) {
data.resize(size);
read(in, data.data(), size);
}
示例14: write
void write(IOutputStream& out, const std::vector<uint8_t>& data) {
write(out, data.data(), data.size());
}
示例15: disableMessages
void DebugMessage::disableMessages(const GLenum source, const GLenum type, const GLenum severity, const std::vector<GLuint> & ids)
{
disableMessages(source, type, severity, static_cast<int>(ids.size()), ids.data());
}