MCPcopy Create free account
hub / github.com/NodeRT/NodeRT / VectorViewWrapper

Class VectorViewWrapper

src/NodeRTLib/ProjectFiles/CollectionsWrap.h:470–718  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468
469template <class T>
470class VectorViewWrapper : NodeRT::WrapperBase {
471 public:
472 static void Init() {
473 HandleScope scope;
474
475 Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
476 s_constructorTemplate.Reset(localRef);
477 localRef->SetClassName(
478 Nan::New<String>("Windows::Foundation::Collections:IVectorView")
479 .ToLocalChecked());
480 localRef->InstanceTemplate()->SetInternalFieldCount(1);
481 Nan::SetIndexedPropertyHandler(localRef->InstanceTemplate(), Get);
482
483 Nan::SetPrototypeMethod(localRef, "getMany", GetMany);
484 Nan::SetPrototypeMethod(localRef, "getAt", GetAt);
485 Nan::SetPrototypeMethod(localRef, "indexOf", IndexOf);
486 Nan::SetPrototypeMethod(localRef, "first", First);
487
488 Nan::SetAccessor(localRef->PrototypeTemplate(),
489 Nan::New<String>("size").ToLocalChecked(), SizeGetter);
490 Nan::SetAccessor(localRef->PrototypeTemplate(),
491 Nan::New<String>("length").ToLocalChecked(), SizeGetter);
492
493 return;
494 }
495
496 static Local<Value> CreateVectorViewWrapper(
497 ::Windows::Foundation::Collections::IVectorView<T> ^ winRtInstance,
498 const std::function<Local<Value>(T)>& getterFunc,
499 const std::function<bool(Local<Value>)>& checkTypeFunc = nullptr,
500 const std::function<T(Local<Value>)>& convertToTypeFunc = nullptr) {
501 EscapableHandleScope scope;
502 if (winRtInstance == nullptr) {
503 return scope.Escape(Undefined());
504 }
505
506 if (s_constructorTemplate.IsEmpty()) {
507 Init();
508 }
509
510 v8::Local<Value> args[] = {Undefined()};
511 Local<FunctionTemplate> localRef =
512 Nan::New<FunctionTemplate>(s_constructorTemplate);
513 Local<Object> objectInstance =
514 Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), 0, args)
515 .ToLocalChecked();
516 if (objectInstance.IsEmpty()) {
517 return scope.Escape(Undefined());
518 }
519
520 VectorViewWrapper<T>* wrapperInstance =
521 new VectorViewWrapper<T>(winRtInstance, getterFunc);
522 wrapperInstance->Wrap(objectInstance);
523 return scope.Escape(objectInstance);
524 }
525
526 virtual ::Platform::Object ^ GetObjectInstance() const override {
527 return _instance;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected