本文整理汇总了C++中Book::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Book::add方法的具体用法?C++ Book::add怎么用?C++ Book::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Book
的用法示例。
在下文中一共展示了Book::add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Setter
void BookWrap::Setter(uint32_t index, Local<Value> value, const PropertyCallbackInfo<Value>& info) {
Isolate* isolate = info.GetIsolate();
HandleScope scope(isolate);
BookWrap* bw = ObjectWrap::Unwrap<BookWrap>(info.This());
Book* b = bw->m_book;
if (value->IsArray()) {
if (index < b->size()) {
Local<v8::Array> arr = Local<v8::Array>::Cast(value);
if (arr->Length() == 3) {
const String::Utf8Value firstname(arr->Get(0)->ToString());
const String::Utf8Value lastname(arr->Get(1)->ToString());
const time_t birthday = time_t(0.001*(*arr->Get(2))->NumberValue());
Person *p = (*b)[index];
p->firstname(*firstname);
p->lastname(*lastname);
p->birthday(birthday);
}
else {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Three elements expected")));
info.GetReturnValue().SetUndefined();
return;
}
}
if (index == b->size()) {
Local<v8::Array> arr = Local<v8::Array>::Cast(value);
if (arr->Length() == 3) {
const String::Utf8Value firstname(arr->Get(0)->ToString());
const String::Utf8Value lastname(arr->Get(1)->ToString());
const time_t birthday = time_t(0.001*(*arr->Get(2))->NumberValue());
Person *p = new Person();
p->firstname(*firstname);
p->lastname(*lastname);
p->birthday(birthday);
b->add(p);
}
else {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Three elements expected")));
info.GetReturnValue().SetUndefined();
return;
}
}
else {
isolate->ThrowException(Exception::RangeError(String::NewFromUtf8(isolate, "Invalid index")));
info.GetReturnValue().SetUndefined();
return;
}
}
else {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Object expected")));
info.GetReturnValue().SetUndefined();
return;
}
info.GetReturnValue().SetUndefined();
}
示例2: main
int main(int argc, char* argv[]) {
Book b;
Person *p1 = new Person();
p1->firstname("Arthur");
p1->lastname("Clarke");
p1->birthday(-1642381200); // 1917-12-16
b.add(p1);
Person *p2 = new Person();
p2->firstname("Peter");
p2->lastname("Hamilton");
p2->birthday(-310352400); // 1960-03-02
b.add(p2);
Person *p3 = new Person();
p3->firstname("Cory");
p3->lastname("Doctorow");
p3->birthday(48553200); // 1971-07-17
b.add(p3);
Person *p4 = new Person();
p4->firstname("Charlie");
p4->lastname("Stross");
p4->birthday(-164221200); // 1964-10-18
b.add(p4);
for(size_t i=0; i<b.size(); ++i) {
Person *p = b[i];
cout << p->to_str() << endl;
}
cout << "Looking for Peter" << endl;
Person *p5 = b.lookup("Peter");
cout << p5->to_str() << endl;
b.remove(1);
cout << "After remove: " << b.size() << endl;
}
示例3: Add
void BookWrap::Add(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
HandleScope scope(isolate);
if (args.Length() == 1) {
BookWrap* bw = ObjectWrap::Unwrap<BookWrap>(args.This());
Book* b = bw->m_book;
PersonWrap* pw = ObjectWrap::Unwrap<PersonWrap>(args[0]->ToObject());
b->add(pw->m_person);
}
else {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Object expected")));
}
args.GetReturnValue().SetUndefined();
}