本文整理汇总了C++中Arguments类的典型用法代码示例。如果您正苦于以下问题:C++ Arguments类的具体用法?C++ Arguments怎么用?C++ Arguments使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Arguments类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST
TEST(CountIsEqual, ValidData)
{
Arguments object = initializeObject();
ASSERT_EQ(object.count(), 2);
}
示例2: while
/**
* Walks the chain of objects accessible from the specified CallFrame.
*/
void GarbageCollector::walk_call_frame(CallFrame* top_call_frame,
AddressDisplacement* offset)
{
CallFrame* call_frame = top_call_frame;
while(call_frame) {
call_frame = displace(call_frame, offset);
// Skip synthetic, non CompiledCode frames
if(!call_frame->compiled_code) {
call_frame = call_frame->previous;
continue;
}
if(call_frame->custom_constant_scope_p() &&
call_frame->constant_scope_ &&
call_frame->constant_scope_->reference_p()) {
call_frame->constant_scope_ =
(ConstantScope*)mark_object(call_frame->constant_scope_);
}
if(call_frame->compiled_code && call_frame->compiled_code->reference_p()) {
call_frame->compiled_code = (CompiledCode*)mark_object(call_frame->compiled_code);
}
if(call_frame->compiled_code && call_frame->stk) {
native_int stack_size = call_frame->compiled_code->stack_size()->to_native();
for(native_int i = 0; i < stack_size; i++) {
Object* obj = call_frame->stk[i];
if(obj && obj->reference_p()) {
call_frame->stk[i] = mark_object(obj);
}
}
}
if(call_frame->multiple_scopes_p() && call_frame->top_scope_) {
call_frame->top_scope_ = (VariableScope*)mark_object(call_frame->top_scope_);
}
if(BlockEnvironment* env = call_frame->block_env()) {
call_frame->set_block_env((BlockEnvironment*)mark_object(env));
}
Arguments* args = displace(call_frame->arguments, offset);
if(!call_frame->inline_method_p() && args) {
args->set_recv(mark_object(args->recv()));
args->set_block(mark_object(args->block()));
if(Tuple* tup = args->argument_container()) {
args->update_argument_container((Tuple*)mark_object(tup));
} else {
Object** ary = displace(args->arguments(), offset);
for(uint32_t i = 0; i < args->total(); i++) {
ary[i] = mark_object(ary[i]);
}
}
}
#ifdef ENABLE_LLVM
if(jit::RuntimeDataHolder* jd = call_frame->jit_data()) {
jd->set_mark();
ObjectMark mark(this);
jd->mark_all(0, mark);
}
if(jit::RuntimeData* rd = call_frame->runtime_data()) {
rd->method_ = (CompiledCode*)mark_object(rd->method());
rd->name_ = (Symbol*)mark_object(rd->name());
rd->module_ = (Module*)mark_object(rd->module());
}
#endif
saw_variable_scope(call_frame, displace(call_frame->scope, offset));
call_frame = call_frame->previous;
}
}
示例3: WKTWriter
Handle<Value> WKTWriter::New(const Arguments& args) {
HandleScope scope;
WKTWriter* writer = new WKTWriter();
writer->Wrap(args.This());
return args.This();
}
示例4: Parse
Arguments ArgumentParser::Parse(const std::string& line)
{
Arguments args;
std::string::size_type pos1 = 0;
for (const auto& type : types)
{
if (pos1 == line.length() || pos1 == std::string::npos)
{
throw cmd::SyntaxError();
}
while (line[pos1] == ' ')
{
if (++pos1 == line.length())
{
throw cmd::SyntaxError();
}
}
switch (type.second)
{
case Type::Grouped :
{
if (line[pos1] == '"') // multiple arguments grouped
{
auto pos2 = line.find('"', pos1 + 1);
if (pos2 == std::string::npos)
{
throw cmd::SyntaxError();
}
args.Push(type.first, line.substr(pos1 + 1, pos2 - pos1 - 1));
pos1 = pos2 + 1;
break;
}
// fall through for single ungrouped argument
}
case Type::Single :
{
auto pos2 = line.find(' ', pos1);
if (pos2 == std::string::npos)
{
args.Push(type.first, line.substr(pos1));
pos1 = std::string::npos;
}
else
{
args.Push(type.first, line.substr(pos1, pos2 - pos1));
pos1 = ++pos2;
}
break;
}
case Type::Multiple :
{
auto pos2 = line.length() - 1;
while (line[pos2] == ' ') --pos2;
args.Push(type.first, line.substr(pos1, pos2 - pos1 + 1));
pos1 = std::string::npos;
break;
}
}
}
if (pos1 < line.length() && pos1 != std::string::npos)
{
throw cmd::SyntaxError();
}
return args;
}
示例5: ThrowException
Handle<Value> ZipFile::readFileSync(const Arguments& args)
{
HandleScope scope;
if (args.Length() != 1 || !args[0]->IsString())
return ThrowException(Exception::TypeError(
String::New("first argument must be a file name inside the zip")));
std::string name = TOSTR(args[0]);
// TODO - enforce valid index
ZipFile* zf = ObjectWrap::Unwrap<ZipFile>(args.This());
if (zf->Busy())
return ThrowException(Exception::Error(String::New("Zipfile already in use..")));
struct zip_file *zf_ptr;
int idx = -1;
std::vector<std::string>::iterator it = std::find(zf->names.begin(), zf->names.end(), name);
if (it!=zf->names.end()) {
idx = distance(zf->names.begin(), it);
}
if (idx == -1) {
std::stringstream s;
s << "No file found by the name of: '" << name << "\n";
return ThrowException(Exception::Error(String::New(s.str().c_str())));
}
if ((zf_ptr=zip_fopen_index(zf->archive, idx, 0)) == NULL) {
zip_fclose(zf_ptr);
std::stringstream s;
s << "cannot open file #" << idx << " in " << name << ": archive error: " << zip_strerror(zf->archive) << "\n";
return ThrowException(Exception::Error(String::New(s.str().c_str())));
}
struct zip_stat st;
zip_stat_index(zf->archive, idx, 0, &st);
std::vector<unsigned char> data;
data.clear();
data.resize( st.size );
int result = 0;
result = (int)zip_fread( zf_ptr, reinterpret_cast<void*> (&data[0]), data.size() );
if (result < 0) {
zip_fclose(zf_ptr);
std::stringstream s;
s << "error reading file #" << idx << " in " << name << ": archive error: " << zip_file_strerror(zf_ptr) << "\n";
return ThrowException(Exception::Error(String::New(s.str().c_str())));
}
#if NODE_VERSION_AT_LEAST(0,3,0)
node::Buffer *retbuf = Buffer::New((char *)&data[0],data.size());
#else
node::Buffer *retbuf = Buffer::New(data.size());
std::memcpy(retbuf->data(), (char *)&data[0], data.size());
#endif
zip_fclose(zf_ptr);
return scope.Close(retbuf->handle_);
}
示例6: LOGD
Handle<Value> ExampleProxy::printMessage(const Arguments& args)
{
LOGD(TAG, "printMessage()");
HandleScope scope;
JNIEnv *env = titanium::JNIScope::getEnv();
if (!env) {
return titanium::JSException::GetJNIEnvironmentError();
}
static jmethodID methodID = NULL;
if (!methodID) {
methodID = env->GetMethodID(ExampleProxy::javaClass, "printMessage", "(Ljava/lang/String;)V");
if (!methodID) {
const char *error = "Couldn't find proxy method 'printMessage' with signature '(Ljava/lang/String;)V'";
LOGE(TAG, error);
return titanium::JSException::Error(error);
}
}
titanium::Proxy* proxy = titanium::Proxy::unwrap(args.Holder());
if (args.Length() < 1) {
char errorStringBuffer[100];
sprintf(errorStringBuffer, "printMessage: Invalid number of arguments. Expected 1 but got %d", args.Length());
return ThrowException(Exception::Error(String::New(errorStringBuffer)));
}
jvalue jArguments[1];
if (!args[0]->IsNull()) {
Local<Value> arg_0 = args[0];
jArguments[0].l =
titanium::TypeConverter::jsValueToJavaString(env, arg_0);
} else {
jArguments[0].l = NULL;
}
jobject javaProxy = proxy->getJavaObject();
env->CallVoidMethodA(javaProxy, methodID, jArguments);
if (!JavaObject::useGlobalRefs) {
env->DeleteLocalRef(javaProxy);
}
env->DeleteLocalRef(jArguments[0].l);
if (env->ExceptionCheck()) {
titanium::JSException::fromJavaException();
env->ExceptionClear();
}
return v8::Undefined();
}
示例7: CreateExternalArray
Handle<Value> CreateExternalArray(const Arguments& args,
ExternalArrayType type,
size_t element_size) {
TryCatch try_catch;
ASSERT_PIN(element_size == 1 || element_size == 2 ||
element_size == 4 || element_size == 8, "CreateExternalArray");
// Currently, only the following constructors are supported:
// TypedArray(unsigned long length)
// TypedArray(ArrayBuffer buffer,
// optional unsigned long byteOffset,
// optional unsigned long length)
Handle<Object> buffer;
int32_t length;
int32_t byteLength;
int32_t byteOffset;
int32_t bufferLength;
if (args.Length() == 0) {
return ThrowException(
String::New("Array constructor must have at least one parameter."));
}
if (args[0]->IsObject() &&
(!args[0]->ToObject()->GetHiddenValue(String::New(kArrayBufferMarkerPropName)).IsEmpty()) ||
(IS_BINARY(args[0]))) {
if (!args[0]->ToObject()->GetHiddenValue(String::New(kArrayBufferMarkerPropName)).IsEmpty()) {
buffer = args[0]->ToObject();
bufferLength = convertToUint(buffer->Get(String::New("byteLength")), &try_catch);
if (try_catch.HasCaught())
return try_catch.Exception();
} else {
buffer = CreateExternalArrayBuffer(args[0])->ToObject();
bufferLength = convertToUint(buffer->Get(String::New("byteLength")), &try_catch);
if (try_catch.HasCaught())
return try_catch.Exception();
}
if (args.Length() < 2 || args[1]->IsUndefined()) {
byteOffset = 0;
} else {
byteOffset = convertToUint(args[1], &try_catch);
if (try_catch.HasCaught()) return try_catch.Exception();
if (byteOffset > bufferLength) {
return ThrowException(String::New("byteOffset out of bounds"));
}
if (byteOffset % element_size != 0) {
return ThrowException(
String::New("byteOffset must be multiple of element_size"));
}
}
if (args.Length() < 3 || args[2]->IsUndefined()) {
byteLength = bufferLength - byteOffset;
length = byteLength / element_size;
if (byteLength % element_size != 0) {
return ThrowException(
String::New("buffer size must be multiple of element_size"));
}
} else {
length = convertToUint(args[2], &try_catch);
if (try_catch.HasCaught())
return try_catch.Exception();
byteLength = length * element_size;
if (byteOffset + byteLength > bufferLength) {
return ThrowException(String::New("length out of bounds"));
}
}
} else {
length = convertToUint(args[0], &try_catch);
byteLength = length * element_size;
byteOffset = 0;
Handle<Value> result = CreateExternalArrayBuffer(byteLength);
if (!result->IsObject())
return result;
buffer = result->ToObject();
}
void* data = buffer->GetIndexedPropertiesExternalArrayData();
ASSERT_PIN(data != NULL, "CreateExternalArray data != NULL");
Handle<Object> array = Object::New();
array->SetIndexedPropertiesToExternalArrayData(
static_cast<uint8_t*>(data) + byteOffset, type, length);
array->Set(String::New("byteLength"), Int32::New(byteLength), ReadOnly);
array->Set(String::New("byteOffset"), Int32::New(byteOffset), ReadOnly);
array->Set(String::New("length"), Int32::New(length), ReadOnly);
array->Set(String::New("BYTES_PER_ELEMENT"), Int32::New(element_size));
array->Set(String::New("buffer"), buffer, ReadOnly);
return array;
}
示例8: defined
ClangParser::ClangParser(Arguments& args)
// VC2005: If shouldClose is set to true, this forces an assert in the CRT on program
// shutdown as stdout hasn't been opened by the app in the first place.
: m_OutputStream(1, false)
{
m_CompilerInvocation.reset(new clang::CompilerInvocation);
// we add a customized macro here to distinguish a clreflect parsing process from a compling using clang
clang::PreprocessorOptions& preprocessor_options = m_CompilerInvocation->getPreprocessorOpts();
preprocessor_options.addMacroDef("__clcpp_parse__");
// Add define/undefine macros to the pre-processor
for (int i = 0; ; i++)
{
std::string macro = args.GetProperty("-D", i);
if (macro == "")
break;
preprocessor_options.addMacroDef(macro.c_str());
}
for (int i = 0; ; i++)
{
std::string macro = args.GetProperty("-U", i);
if (macro == "")
break;
preprocessor_options.addMacroUndef(macro.c_str());
}
// Setup the language parsing options for C++
clang::LangOptions& lang_options = *m_CompilerInvocation->getLangOpts();
m_CompilerInvocation->setLangDefaults(lang_options, clang::IK_CXX, clang::LangStandard::lang_cxx03);
lang_options.CPlusPlus = 1;
lang_options.Bool = 1;
lang_options.RTTI = 0;
#if defined(CLCPP_USING_MSVC)
lang_options.MicrosoftExt = 1;
lang_options.MicrosoftMode = 1;
lang_options.MSBitfields = 1;
//
// This is MSVC specific to get STL compiling with clang. MSVC doesn't do semantic analysis
// of templates until instantiation, whereas clang will try to resolve non type-based function
// calls. In MSVC STL land, this causes hundreds of errors referencing '_invalid_parameter_noinfo'.
//
// The problem in a nutshell:
//
// template <typename TYPE> void A()
// {
// // Causes an error in clang because B() is not defined yet, MSVC is fine
// B();
// }
// void B() { }
//
lang_options.DelayedTemplateParsing = 1;
#endif // CLCPP_USING_MSVC
// Gather C++ header searches from the command-line
clang::HeaderSearchOptions& header_search_options = m_CompilerInvocation->getHeaderSearchOpts();
for (int i = 0; ; i++)
{
std::string include = args.GetProperty("-i", i);
if (include == "")
break;
header_search_options.AddPath(include.c_str(), clang::frontend::Angled, false, false, false);
}
for (int i = 0; ; i++)
{
std::string include = args.GetProperty("-isystem", i);
if (include == "")
break;
header_search_options.AddPath(include.c_str(), clang::frontend::System, false, false, false);
}
// Setup diagnostics output; MSVC line-clicking and suppress warnings from system headers
#if defined(CLCPP_USING_MSVC)
m_DiagnosticOptions.Format = m_DiagnosticOptions.Msvc;
#else
m_DiagnosticOptions.Format = m_DiagnosticOptions.Clang;
#endif // CLCPP_USING_MSVC
clang::TextDiagnosticPrinter *client = new clang::TextDiagnosticPrinter(m_OutputStream, m_DiagnosticOptions);
m_CompilerInstance.createDiagnostics(0, NULL, client);
m_CompilerInstance.getDiagnostics().setSuppressSystemWarnings(true);
// Setup target options - ensure record layout calculations use the MSVC C++ ABI
clang::TargetOptions& target_options = m_CompilerInvocation->getTargetOpts();
target_options.Triple = llvm::sys::getDefaultTargetTriple();
#if defined(CLCPP_USING_MSVC)
target_options.CXXABI = "microsoft";
#else
target_options.CXXABI = "itanium";
#endif // CLCPP_USING_MSVC
m_TargetInfo.reset(clang::TargetInfo::CreateTargetInfo(m_CompilerInstance.getDiagnostics(), target_options));
m_CompilerInstance.setTarget(m_TargetInfo.take());
// Set the invokation on the instance
m_CompilerInstance.createFileManager();
m_CompilerInstance.createSourceManager(m_CompilerInstance.getFileManager());
m_CompilerInstance.setInvocation(m_CompilerInvocation.take());
}
示例9: ThrowException
Handle<Value> Database::Query(const Arguments& args) {
HandleScope scope;
REQ_STR_ARG(0, sql);
Local<Function> cb;
int paramCount = 0;
Parameter* params;
Database* dbo = ObjectWrap::Unwrap<Database>(args.This());
struct query_request *prep_req = (struct query_request *)
calloc(1, sizeof(struct query_request));
if (!prep_req) {
V8::LowMemoryNotification();
return ThrowException(Exception::Error(String::New("Could not allocate enough memory")));
}
// populate prep_req->params if parameters were supplied
//
if (args.Length() > 2)
{
if ( !args[1]->IsArray() )
{
return ThrowException(Exception::TypeError(
String::New("Argument 1 must be an Array"))
);
}
else if ( !args[2]->IsFunction() )
{
return ThrowException(Exception::TypeError(
String::New("Argument 2 must be a Function"))
);
}
Local<Array> values = Local<Array>::Cast(args[1]);
cb = Local<Function>::Cast(args[2]);
prep_req->paramCount = paramCount = values->Length();
prep_req->params = params = new Parameter[paramCount];
for (int i = 0; i < paramCount; i++)
{
Local<Value> value = values->Get(i);
params[i].size = 0;
params[i].length = NULL;
params[i].buffer_length = 0;
if (value->IsString())
{
String::Utf8Value string(value);
params[i].c_type = SQL_C_CHAR;
params[i].type = SQL_VARCHAR;
params[i].length = SQL_NTS;
params[i].buffer = malloc(string.length() + 1);
params[i].buffer_length = string.length() + 1;
params[i].size = string.length() + 1;
strcpy((char*)params[i].buffer, *string);
}
else if (value->IsNull())
{
params[i].c_type = SQL_C_DEFAULT;
params[i].type = SQL_NULL_DATA;
params[i].length = SQL_NULL_DATA;
}
else if (value->IsInt32())
{
int64_t *number = new int64_t(value->IntegerValue());
params[i].c_type = SQL_C_LONG;
params[i].type = SQL_INTEGER;
params[i].buffer = number;
}
else if (value->IsNumber())
{
double *number = new double(value->NumberValue());
params[i].c_type = SQL_C_DOUBLE;
params[i].type = SQL_DECIMAL;
params[i].buffer = number;
}
else if (value->IsBoolean())
{
bool *boolean = new bool(value->BooleanValue());
params[i].c_type = SQL_C_BIT;
params[i].type = SQL_BIT;
params[i].buffer = boolean;
}
}
}
else
{
if ( !args[1]->IsFunction() )
{
return ThrowException(Exception::TypeError(
String::New("Argument 1 must be a Function"))
//.........这里部分代码省略.........
示例10: ListTablesCall
/* Constructor */
ListTablesCall(const Arguments &args) :
NativeCFunctionCall_2_<int, SessionImpl *, const char *>(NULL, args),
list(),
isolate(args.GetIsolate())
{
}
示例11: MemoryObject
/* static */
Handle<Value> MemoryObject::New(const Arguments& args)
{
HandleScope scope;
MemoryObject *cl = new MemoryObject(args.This());
return args.This();
}
示例12: New
static Handle<Value> New(const Arguments &args)
{
Rot13 *rot13 = new Rot13();
rot13->Wrap(args.This());
return args.This();
}
示例13: App
Handle<Value> App::New(const Arguments& args) {
HandleScope scope;
App* obj = new App();
obj->Wrap(args.This());
return scope.Close(args.This());
}
示例14: main
int main(int argc, const char* argv[])
{
//
// Parse arguments
//
Arguments arguments;
std::string makeFile("project.pmk");
std::string fbxFile;
bool fromFbx = false; // Create the entire wallpaper from FBX.
for (int i = 1; i < argc; ++i)
{
if (strncmp(argv[i], "-h", 2) == 0)
{
printUsage();
return EXIT_SUCCESS;
}
else if (strncmp(argv[i], "-v", 2) == 0)
{
printVersion();
return EXIT_SUCCESS;
}
else if (strncmp(argv[i], "-f", 2) == 0)
{
i++;
if (i == argc)
{
logError("The project make file is missing!\n");
printUsage();
return EXIT_FAILURE;
}
makeFile = std::string(argv[i]);
}
else
{
if (i == argc - 1)
{
fbxFile = argv[i];
fromFbx = true;
}
else
{
logError("Unknown command line arguments.");
printUsage();
return EXIT_FAILURE;
}
}
}
// Parse the configuration.
if (!fromFbx)
{
if (!arguments.parse(makeFile.c_str()))
{
return EXIT_FAILURE;
}
}
else
{
arguments.fromFbxFile(fbxFile);
}
//
// Delete the old project if exists
//
char cmdline[1024];
#if defined WIN32
sprintf_s(cmdline, 1024, "rd /s /q %s", arguments.shortProjectName.c_str());
system(cmdline);
#endif
//
// Create the project
//
logInfo("Creating the project.");
MakeProject makeProject(arguments);
if (!makeProject.run(fromFbx))
{
return EXIT_FAILURE;
}
logInfo("Project %s has been created!", arguments.projectName.c_str());
//
// Run fbxtool and copy the resource to the application folder.
//
#if defined WIN32
sprintf_s(cmdline, 1024, "fbxtool.exe -meshformat pmh -meshattrib a %s", fbxFile.c_str());
int exitCode = system(cmdline);
sprintf_s(cmdline, 1024, "xcopy /E /i res %s\\application\\res", arguments.shortProjectName.c_str());
system(cmdline);
system("rd /s /q res");
#endif
// If debugger is present, a pause is required to keep the console output
// visible. Otherwise the pause is automatic.
//.........这里部分代码省略.........
示例15: ThrowException
Handle<Value> TiTitaniumObject::_globalInclude(void*, TiObject*, const Arguments& args)
{
if (args.Length() < 2)
{
return ThrowException(String::New(Ti::Msg::Missing_argument));
}
string id = *String::Utf8Value(args[0]->ToString());
string parentFolder = *String::Utf8Value(args[1]->ToString());
// CommonJS path rules
if (id.find("/") == 0) {
id.replace(id.find("/"), std::string("/").length(), rootFolder);
}
else if (id.find("./") == 0) {
id.replace(id.find("./"), std::string("./").length(), parentFolder);
}
else if (id.find("../") == 0) {
// count ../../../ in id and strip off back of parentFolder
int count = 0;
size_t idx = 0;
size_t pos = 0;
while (true) {
idx = id.find("../", pos);
if (idx == std::string::npos) {
break;
} else {
pos = idx + 3;
count++;
}
}
// strip leading ../../ off module id
id = id.substr(pos);
// strip paths off the parent folder
idx = 0;
pos = parentFolder.size();
for (int i = 0; i < count; i++) {
idx = parentFolder.find_last_of("/", pos);
pos = idx - 1;
}
if (idx == std::string::npos) {
return ThrowException(String::New("Unable to find module"));
}
parentFolder = parentFolder.substr(0, idx + 1);
id = parentFolder + id;
}
else {
string tempId = rootFolder + id;
ifstream ifs((tempId).c_str());
if (!ifs) {
id = parentFolder + id;
}
else {
id = rootFolder + id;
}
}
string filename = id;
string javascript;
{
ifstream ifs((filename).c_str());
if (!ifs)
{
Local<Value> taggedMessage = String::New((string(Ti::Msg::No_such_native_module) + " " + id).c_str());
return ThrowException(taggedMessage);
}
getline(ifs, javascript, string::traits_type::to_char_type(string::traits_type::eof()));
ifs.close();
}
// wrap the module
{
size_t idx = filename.find_last_of("/");
parentFolder = filename.substr(0, idx + 1);
static const string preWrap = "Ti.include = function (id) { Ti.globalInclude(id, '" + parentFolder + "')};\n";
javascript = preWrap + javascript;
}
TryCatch tryCatch;
Handle<Script> compiledScript = Script::Compile(String::New(javascript.c_str()), String::New(filename.c_str()));
if (compiledScript.IsEmpty())
{
DisplayExceptionLine(tryCatch);
return tryCatch.ReThrow();
}
Persistent<Value> result = Persistent<Value>::New(compiledScript->Run());
if (result.IsEmpty())
{
return tryCatch.ReThrow();
}
//.........这里部分代码省略.........