本文整理汇总了C++中scoped_array类的典型用法代码示例。如果您正苦于以下问题:C++ scoped_array类的具体用法?C++ scoped_array怎么用?C++ scoped_array使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了scoped_array类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buf
void XEReader::readPortAliases(PortAliases &aliases)
{
const XESector *XNSector = xe.getXNSector();
if (!XNSector)
return;
uint64_t length = XNSector->getLength();
const scoped_array<char> buf(new char[length + 1]);
if (!XNSector->getData(buf.get())) {
std::cerr << "Error reading XN from \"" << xe.getFileName() << "\"";
std::cerr << std::endl;
std::exit(1);
}
if (length < 8) {
std::cerr << "Error unexpected XN sector length" << std::endl;
std::exit(1);
}
length -= 8;
buf[length] = '\0';
xmlDoc *doc = xmlReadDoc(BAD_CAST buf.get(), "platform_def.xn", NULL, 0);
xmlDoc *newDoc = applyXSLTTransform(doc, XNTransform);
xmlFreeDoc(doc);
if (!checkDocAgainstSchema(newDoc, XNSchema, sizeof(XNSchema)))
std::exit(1);
::readPortAliases(aliases, xmlDocGetRootElement(newDoc));
xmlFreeDoc(newDoc);
}
示例2: LCSLength
void LCSLength( scoped_array<scoped_array<size_t> >& C ,vector_start_at_zero<SgNode*>& A, vector_start_at_zero<SgNode*>& B )
{
int m = A.size()+1;
int n = B.size()+1;
C.reset(new scoped_array<size_t>[m]);
for (int i = 0 ; i < m; i++)
C[i].reset(new size_t[n]);
for (size_t i = 0 ; i <= A.size() ; i++)
C[i][0]=0;
for (size_t i = 0 ; i <= B.size() ; i++)
C[0][i]=0;
for (size_t i = 1 ; i <= A.size() ; i++)
for (size_t j = 1 ; j <= B.size() ; j++)
{
if(isEqual(A[i],B[j]))
C[i][j] = C[i-1][j-1]+1;
else
C[i][j] = C[i][j-1] > C[i-1][j] ? C[i][j-1] : C[i-1][j];
}
}
示例3: loadFileData
bool loadFileData(const boost::filesystem::path& path,
scoped_array<char>& fileData,
int& fileSize) {
fs::ifstream ifs(path, ifstream::in | ifstream::binary);
if (!ifs) {
ostringstream oss;
oss << "Could not open file \"" << path << "\".";
throw rlvm::Exception(oss.str());
}
ifs.seekg(0, ios::end);
fileSize = ifs.tellg();
ifs.seekg(0, ios::beg);
fileData.reset(new char[fileSize]);
ifs.read(fileData.get(), fileSize);
return !ifs.good();
}
示例4: WriteConsoleInput
void ConsoleHandler::WriteConsoleInput(HANDLE hStdIn, scoped_array<INPUT_RECORD>& consoleInputs, size_t& consoleInputCount, size_t maxConsoleInputCount)
{
if (consoleInputCount > 0)
{
DWORD dwTextWritten = 0;
::WriteConsoleInput(hStdIn, consoleInputs.get(), static_cast<DWORD>(consoleInputCount), &dwTextWritten);
}
if (maxConsoleInputCount > 0)
{
consoleInputs.reset(new INPUT_RECORD[maxConsoleInputCount]);
::ZeroMemory(consoleInputs.get(), sizeof(INPUT_RECORD)*maxConsoleInputCount);
}
else
{
consoleInputs.reset();
}
consoleInputCount = 0;
}
示例5: swap
template<class T> inline void swap(scoped_array<T> & a, scoped_array<T> & b) // never throws
{
a.swap(b);
}
示例6: swap
inline void swap(scoped_array<T> & a, scoped_array<T> & b)
{
a.swap(b);
}
示例7: createSystemFromConfig
static inline std::auto_ptr<SystemState>
createSystemFromConfig(const char *filename, const XESector *configSector)
{
uint64_t length = configSector->getLength();
const scoped_array<char> buf(new char[length + 1]);
if (!configSector->getData(buf.get())) {
std::cerr << "Error reading config from \"" << filename << "\"" << std::endl;
std::exit(1);
}
if (length < 8) {
std::cerr << "Error unexpected config config sector length" << std::endl;
std::exit(1);
}
length -= 8;
buf[length] = '\0';
/*
* this initialize the library and check potential ABI mismatches
* between the version it was compiled for and the actual shared
* library used.
*/
LIBXML_TEST_VERSION
xmlDoc *doc = xmlReadDoc((xmlChar*)buf.get(), "config.xml", NULL, 0);
xmlRelaxNGParserCtxtPtr schemaContext =
xmlRelaxNGNewMemParserCtxt(configSchema, sizeof(configSchema));
xmlRelaxNGPtr schema = xmlRelaxNGParse(schemaContext);
xmlRelaxNGValidCtxtPtr validationContext =
xmlRelaxNGNewValidCtxt(schema);
if (xmlRelaxNGValidateDoc(validationContext, doc) != 0) {
std::exit(1);
}
xmlNode *root = xmlDocGetRootElement(doc);
xmlNode *system = findChild(root, "System");
xmlNode *nodes = findChild(system, "Nodes");
std::auto_ptr<SystemState> systemState(new SystemState);
std::map<long,Node*> nodeNumberMap;
for (xmlNode *child = nodes->children; child; child = child->next) {
if (child->type != XML_ELEMENT_NODE ||
strcmp("Node", (char*)child->name) != 0)
continue;
systemState->addNode(createNodeFromConfig(child, nodeNumberMap));
}
xmlNode *connections = findChild(system, "Connections");
for (xmlNode *child = connections->children; child; child = child->next) {
if (child->type != XML_ELEMENT_NODE ||
strcmp("SLink", (char*)child->name) != 0)
continue;
long nodeID1, link1, nodeID2, link2;
if (!parseXLinkEnd(findAttribute(child, "end1"), nodeID1, link1)) {
std::cerr << "Failed to parse \"end1\" attribute" << std::endl;
std::exit(1);
}
if (!parseXLinkEnd(findAttribute(child, "end2"), nodeID2, link2)) {
std::cerr << "Failed to parse \"end2\" attribute" << std::endl;
std::exit(1);
}
Node *node1 = lookupNodeChecked(nodeNumberMap, nodeID1);
if (link1 >= node1->getNumXLinks()) {
std::cerr << "Invalid sLink number " << link1 << std::endl;
std::exit(1);
}
Node *node2 = lookupNodeChecked(nodeNumberMap, nodeID2);
if (link2 >= node2->getNumXLinks()) {
std::cerr << "Invalid sLink number " << link2 << std::endl;
std::exit(1);
}
node1->connectXLink(link1, node2, link2);
node2->connectXLink(link2, node1, link1);
}
xmlNode *jtag = findChild(system, "JtagChain");
unsigned jtagIndex = 0;
for (xmlNode *child = jtag->children; child; child = child->next) {
if (child->type != XML_ELEMENT_NODE ||
strcmp("Node", (char*)child->name) != 0)
continue;
long nodeID = readNumberAttribute(child, "id");
lookupNodeChecked(nodeNumberMap, nodeID)->setJtagIndex(jtagIndex++);
}
systemState->finalize();
xmlFreeDoc(doc);
xmlCleanupParser();
return systemState;
}
示例8: readElf
static void readElf(const char *filename, const XEElfSector *elfSector,
Core &core, std::auto_ptr<CoreSymbolInfo> &SI,
std::map<Core*,uint32_t> &entryPoints)
{
uint64_t ElfSize = elfSector->getElfSize();
const scoped_array<char> buf(new char[ElfSize]);
if (!elfSector->getElfData(buf.get())) {
std::cerr << "Error reading elf data from \"" << filename << "\"" << std::endl;
std::exit(1);
}
if (elf_version(EV_CURRENT) == EV_NONE) {
std::cerr << "ELF library intialisation failed: "
<< elf_errmsg(-1) << std::endl;
std::exit(1);
}
Elf *e;
if ((e = elf_memory(buf.get(), ElfSize)) == NULL) {
std::cerr << "Error reading ELF: " << elf_errmsg(-1) << std::endl;
std::exit(1);
}
if (elf_kind(e) != ELF_K_ELF) {
std::cerr << filename << " is not an ELF object" << std::endl;
std::exit(1);
}
GElf_Ehdr ehdr;
if (gelf_getehdr(e, &ehdr) == NULL) {
std::cerr << "Reading ELF header failed: " << elf_errmsg(-1) << std::endl;
std::exit(1);
}
if (ehdr.e_machine != XCORE_ELF_MACHINE) {
std::cerr << "Not a XCore ELF" << std::endl;
std::exit(1);
}
if (ehdr.e_entry != 0) {
entryPoints.insert(std::make_pair(&core, (uint32_t)ehdr.e_entry));
}
unsigned num_phdrs = ehdr.e_phnum;
if (num_phdrs == 0) {
std::cerr << "No ELF program headers" << std::endl;
std::exit(1);
}
core.resetCaches();
uint32_t ram_base = core.ram_base;
uint32_t ram_size = core.getRamSize();
for (unsigned i = 0; i < num_phdrs; i++) {
GElf_Phdr phdr;
if (gelf_getphdr(e, i, &phdr) == NULL) {
std::cerr << "Reading ELF program header " << i << " failed: " << elf_errmsg(-1) << std::endl;
std::exit(1);
}
if (phdr.p_filesz == 0) {
continue;
}
if (phdr.p_offset > ElfSize) {
std::cerr << "Invalid offet in ELF program header" << i << std::endl;
std::exit(1);
}
if (!core.isValidAddress(phdr.p_paddr) ||
!core.isValidAddress(phdr.p_paddr + phdr.p_memsz)) {
std::cerr << "Error data from ELF program header " << i;
std::cerr << " does not fit in memory" << std::endl;
std::exit(1);
}
core.writeMemory(phdr.p_paddr, &buf[phdr.p_offset], phdr.p_filesz);
}
readSymbols(e, ram_base, ram_base + ram_size, SI);
elf_end(e);
}
示例9: swap
void swap(scoped_array<T, P, R, D> & a, scoped_array<T, P, R, D> & b)
{
a.swap(b);
}
示例10: buf
int BootSequenceStepElf::execute(ExecutionState &state)
{
SystemState &sys = state.sys;
BreakpointManager &BM = state.breakpointManager;
uint64_t ElfSize = elfSector->getElfSize();
const scoped_array<char> buf(new char[ElfSize]);
if (!elfSector->getElfData(buf.get())) {
std::cerr << "Error reading ELF data from ELF sector" << std::endl;
std::exit(1);
}
Elf *e;
if ((e = elf_memory(buf.get(), ElfSize)) == NULL) {
std::cerr << "Error reading ELF: " << elf_errmsg(-1) << std::endl;
std::exit(1);
}
if (elf_kind(e) != ELF_K_ELF) {
std::cerr << "ELF section is not an ELF object" << std::endl;
std::exit(1);
}
GElf_Ehdr ehdr;
if (gelf_getehdr(e, &ehdr) == NULL) {
std::cerr << "Reading ELF header failed: " << elf_errmsg(-1) << std::endl;
std::exit(1);
}
if (ehdr.e_machine != XCORE_ELF_MACHINE &&
ehdr.e_machine != XCORE_ELF_MACHINE_OLD) {
std::cerr << "Not a XCore ELF" << std::endl;
std::exit(1);
}
uint32_t entryPoint = core->getRamBase();
if (ehdr.e_entry != 0) {
if (core->isValidRamAddress(ehdr.e_entry)) {
entryPoint = ehdr.e_entry;
} else {
std::cout << "Warning: invalid ELF entry point 0x";
std::cout << std::hex << ehdr.e_entry << std::dec << "\n";
}
}
uint32_t ram_base = core->getRamBase();
uint32_t ram_size = core->getRamSize();
if (loadImage) {
unsigned num_phdrs = ehdr.e_phnum;
if (num_phdrs == 0) {
std::cerr << "No ELF program headers" << std::endl;
std::exit(1);
}
for (unsigned i = 0; i < num_phdrs; i++) {
GElf_Phdr phdr;
if (gelf_getphdr(e, i, &phdr) == NULL) {
std::cerr << "Reading ELF program header " << i << " failed: ";
std::cerr << elf_errmsg(-1) << std::endl;
std::exit(1);
}
if (phdr.p_filesz == 0) {
continue;
}
if (phdr.p_offset > ElfSize) {
std::cerr << "Invalid offet in ELF program header" << i << std::endl;
std::exit(1);
}
if (!core->isValidRamAddress(phdr.p_paddr) ||
!core->isValidRamAddress(phdr.p_paddr + phdr.p_memsz)) {
std::cerr << "Error data from ELF program header " << i;
std::cerr << " does not fit in memory" << std::endl;
std::exit(1);
}
core->writeMemory(phdr.p_paddr, &buf[phdr.p_offset], phdr.p_filesz);
}
}
std::auto_ptr<CoreSymbolInfo> CSI;
readSymbols(e, ram_base, ram_base + ram_size, CSI);
SymbolInfo &SI = sys.getSymbolInfo();
SI.add(core, CSI);
// Patch in syscall instruction at the syscall address.
if (const ElfSymbol *syscallSym = SI.getGlobalSymbol(core, "_DoSyscall")) {
if (!BM.setBreakpoint(*core, syscallSym->value, BreakpointType::Syscall)) {
std::cout << "Warning: invalid _DoSyscall address "
<< std::hex << syscallSym->value << std::dec << "\n";
}
}
// Patch in exception instruction at the exception address
if (const ElfSymbol *doExceptionSym = SI.getGlobalSymbol(core, "_DoException")) {
if (!BM.setBreakpoint(*core, doExceptionSym->value,
BreakpointType::Exception)) {
std::cout << "Warning: invalid _DoException address "
<< std::hex << doExceptionSym->value << std::dec << "\n";
}
}
if (useElfEntryPoint) {
sys.schedule(core->getThread(0));
core->getThread(0).setPcFromAddress(entryPoint);
}
elf_end(e);
return 0;
}
示例11:
inline bool operator != (T* __lhs, const scoped_array<T>& __rhs)
{
return __lhs != __rhs.get();
}
示例12: createSystemFromConfig
static std::auto_ptr<SystemState>
createSystemFromConfig(const std::string &filename,
const XESector *configSector,
bool tracing)
{
uint64_t length = configSector->getLength();
const scoped_array<char> buf(new char[length + 1]);
if (!configSector->getData(buf.get())) {
std::cerr << "Error reading config from \"" << filename << "\"" << std::endl;
std::exit(1);
}
if (length < 8) {
std::cerr << "Error unexpected config config sector length" << std::endl;
std::exit(1);
}
length -= 8;
buf[length] = '\0';
xmlDoc *doc = xmlReadDoc(BAD_CAST buf.get(), "config.xml", NULL, 0);
if (!checkDocAgainstSchema(doc, configSchema, sizeof(configSchema)))
std::exit(1);
xmlNode *root = xmlDocGetRootElement(doc);
xmlNode *system = findChild(root, "System");
xmlNode *nodes = findChild(system, "Nodes");
std::auto_ptr<SystemState> systemState(new SystemState(tracing));
std::map<long,Node*> nodeNumberMap;
for (xmlNode *child = nodes->children; child; child = child->next) {
if (child->type != XML_ELEMENT_NODE ||
strcmp("Node", (char*)child->name) != 0)
continue;
systemState->addNode(createNodeFromConfig(child, nodeNumberMap, tracing));
}
xmlNode *connections = findChild(system, "Connections");
for (xmlNode *child = connections->children; child; child = child->next) {
if (child->type != XML_ELEMENT_NODE ||
strcmp("SLink", (char*)child->name) != 0)
continue;
long nodeID1, link1, nodeID2, link2;
if (!parseXLinkEnd(findAttribute(child, "end1"), nodeID1, link1)) {
std::cerr << "Failed to parse \"end1\" attribute" << std::endl;
std::exit(1);
}
if (!parseXLinkEnd(findAttribute(child, "end2"), nodeID2, link2)) {
std::cerr << "Failed to parse \"end2\" attribute" << std::endl;
std::exit(1);
}
Node *node1 = lookupNodeChecked(nodeNumberMap, nodeID1);
if (link1 >= node1->getNumXLinks()) {
std::cerr << "Invalid sLink number " << link1 << std::endl;
std::exit(1);
}
Node *node2 = lookupNodeChecked(nodeNumberMap, nodeID2);
if (link2 >= node2->getNumXLinks()) {
std::cerr << "Invalid sLink number " << link2 << std::endl;
std::exit(1);
}
node1->connectXLink(link1, node2, link2);
node2->connectXLink(link2, node1, link1);
}
xmlNode *jtag = findChild(system, "JtagChain");
unsigned jtagIndex = 0;
for (xmlNode *child = jtag->children; child; child = child->next) {
if (child->type != XML_ELEMENT_NODE ||
strcmp("Node", (char*)child->name) != 0)
continue;
long nodeID = readNumberAttribute(child, "id");
lookupNodeChecked(nodeNumberMap, nodeID)->setJtagIndex(jtagIndex++);
}
systemState->finalize();
xmlFreeDoc(doc);
return systemState;
}
示例13: init_problem
// Initialize the data for the problem. Requires num_devices to be known.
void init_problem() {
if(num_devices == 0) {
checkError(-1, "No devices");
}
input_a.reset(num_devices);
input_b.reset(num_devices);
output.reset(num_devices);
ref_output.reset(num_devices);
// Generate input vectors A and B and the reference output consisting
// of a total of N elements.
// We create separate arrays for each device so that each device has an
// aligned buffer.
for(unsigned i = 0; i < num_devices; ++i) {
input_a[i].reset(n_per_device[i]);
input_b[i].reset(n_per_device[i]);
output[i].reset(n_per_device[i]);
ref_output[i].reset(n_per_device[i]);
for(unsigned j = 0; j < n_per_device[i]; ++j) {
input_a[i][j] = rand_float();
input_b[i][j] = rand_float();
ref_output[i][j] = input_a[i][j] + input_b[i][j];
}
}
}
示例14: init_problem
// Initialize the data for the problem. Requires num_devices to be known.
void init_problem() {
if(num_devices == 0) {
checkError(-1, "No devices");
}
printf("Generating input matrices\n");
input_a.reset(num_devices);
output.reset(num_devices);
for(unsigned i = 0; i < num_devices; ++i) {
input_a[i].reset(A_height * A_width);
output[i].reset(C_height * C_width);
// printf("array A elements\n");
for(unsigned j = 0; j < A_height * A_width; ++j) {
if(((j%1028)==0) || ((j%1028)>=1025) || ((j/1028)==0) || (j/1028)==1025) {
input_a[i][j] = 0.0f;
}
else {
input_a[i][j] = rand_float();
}
}
}
}
示例15: compute_reference
void compute_reference() {
// Compute the reference output.
printf("Computing reference output\n");
ref_output.reset(C_height * C_width);
for(unsigned y = 0; y < C_height; ++y) {
for(unsigned x = 0; x < C_width; ++x) {
float sum = 0.0f;
if(y>=1 && x>=1 && x<=1024)
sum = 0.2*(input_a[0][(y)*A_width+x] + input_a[0][(y-1)*A_width+x] + input_a[0][(y+1)*A_width+x] + input_a[0][(y)*A_width+x-1] + input_a[0][(y)*A_width+x+1]);
ref_output[y*1028+x] = sum;
}
}
}