填充矢量模板化类型

问题描述

我正在尝试在实体组件系统中开发Views。

我在实体管理器中有一个名为View的函数,该函数返回Type T的所有组件。 像这样适用于单个模板。

  requestForm: FormGroup;
  sampleRequest: SampleRequest = new SampleRequest();
  isSuccessful = false;
  isFailed = false;
  isProgress = false;
  errMsg: string;

  constructor(private fb: FormBuilder,private userService: UserService,private tokenStorage: TokenStorageService) { }

  ngOnInit() {
    this.requestForm = this.fb.group({
      title : ['',Validators.required],category : ['',description: ['',quantity: ['',[Validators.required,Validators.pattern]]
    });

  }



  onSubmit() {
    this.sampleRequest.title = this.requestForm.get('title').value;
    this.sampleRequest.category.id = this.requestForm.get('category').value; //here is the problem
    this.sampleRequest.user.id = this.tokenStorage.getUser().id;  //and here
    this.sampleRequest.description = this.requestForm.get('description').value;
    this.sampleRequest.quantity = this.requestForm.get('quantity').value;
    console.log(this.sampleRequest);
    this.userService.newSampleRequest(this.sampleRequest)
      .subscribe(
        data => {
          this.isSuccessful = true;
          this.isProgress = true;
        },error => {
          this.isFailed = true;
          this.isProgress = true;
          this.errMsg = error.error.message;
        }
      );
  }

}

ECSViewTest只是T的元组的Vector的包装,稍后将对其进行扩展。

ECSViewTest<T> View()
        {
            //--check if valid code removed

            ComponentArray<T>* componentArray = (ComponentArray<T>*)m_ComponentArrays.at(typeHash);

            ECSViewTest<T> view;
            for (size_t i = 0; i < componentArray->m_Size; i++)
            {
                view.sets.push_back(&componentArray->m_ComponentArray[i]);

            }

            return view;
        }

我的问题是,是否可以针对多种类型实现此功能,即视图可以找到并返回模板中2种或更多给定类型的所有组件。

template<class... Types>
    class ECSViewTest
    {
    public:

        //----------

        std::vector< std::tuple<Types*...>> sets;

        //IteraTOR IMPLEMENTATION
        //EXTRACT TUPLE DATA

    };

如何“遍历”每种Type中的类型以提取每个组件的数据?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)