Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void explicit_euler(T period, T time_step, !тутдолжнабытьфункция);
- std::vector<vector_type> quadratic(const std::vector<object_type *>& objects);
- std::vector<vector_type> finit_element(const std::vector<object_type *>& objects);
- void simulate (QString state_directory_name,
- T period,
- T time_step,
- time_method time = time_method::explicit_euler,
- force_method force = force_method::quadratic);
- enum class time_method { explicit_euler };
- enum class force_method { quadratic, finit_element };
- using system_type = gravity::system<T, dim>;
- using object_type = gravity::object<T, dim>;
- using vector_type = geometry::vector<T, dim>;
- template<typename T, size_t dim>
- void model<T, dim>::simulate (QString state_directory_name,
- T period, T time_step,
- time_method time,
- force_method force)
- {
- std::function<std::vector<vector_type>(const std::vector<object_type *>&)> method;
- switch(force)
- {
- case force_method::quadratic:
- {
- method = quadratic;
- break;
- }
- case force_method::finit_element:
- {
- method = finit_element;
- break;
- }
- }
- switch(time)
- {
- case time_method::explicit_euler:
- {
- explicit_euler(period, time_step, method);
- break;
- }
- }
- }
- std::vector<vector_type> quadratic(const std::vector<object_type *>& objects);
- std::vector<vector_type> finit_element(const std::vector<object_type *>& objects);
- std::function<std::vector<vector_type>(const std::vector<object_type *>&)>
- #include<vector>
- #include<array>
- #include<functional>
- using vector_type = std::array<int,3>;
- using object_type = vector_type;
- std::vector<vector_type> quadratic(const std::vector<object_type*>& objects){
- return {std::array<int,3>{1,2,3}};
- }
- std::vector<vector_type> finit_element(const std::vector<object_type*>& objects){
- return {};
- }
- volatile static int v = 0;
- auto foo(){
- std::function<std::vector<vector_type>(const std::vector<object_type*>&)> fn;
- if(v == 0)
- fn = quadratic;
- else
- fn = finit_element;
- return 0;
- }
- #include<vector>
- #include<array>
- #include<functional>
- #include<iostream>
- class MyInt{
- int v_;
- public:
- MyInt(int v): v_{v} { }
- // Функция - член
- void setV(int v) { v_ = v; }
- int getV()const {return v_;}
- // Статическая функция
- static int static_setV(MyInt& self, int v) {
- return self.v_ = v; // Обратите внимание, есть доступ к private - полю
- // Кроме того, для шаблонных типов доступны все соответствующие типы шаблона
- }
- };
- // Свободная функция
- void free_setV(MyInt& i, int v){
- i.setV(v); // Нет доступа к private-полю, если не объявлена дружественной
- }
- int main (){
- std::function<void(MyInt&, int)> set_value_fn;
- MyInt i {0};
- std::cout << i.getV() <<std::endl;
- set_value_fn = MyInt::static_setV;
- set_value_fn(i, 1);
- std::cout << i.getV() <<std::endl;
- set_value_fn = free_setV;
- set_value_fn(i, 2);
- std::cout << i.getV() <<std::endl;
- set_value_fn = &MyInt::setV;
- set_value_fn(i, 3);
- std::cout << i.getV() <<std::endl;
- return 0;
- }
- template<typename T, size_t dim>
- void model<T, dim>::simulate (QString state_directory_name,
- T period, T time_step,
- time_method time,
- force_method force)
- {
- std::function<std::vector<vector_type>(const model<T, dim>&, const std::vector<object_type *>&)> method;
- switch(force)
- {
- case force_method::quadratic:
- {
- method = &model<T,dim>::quadratic;
- break;
- }
- case force_method::finit_element:
- {
- method = &model<T,dim>::finit_element;
- break;
- }
- }
- switch(time)
- {
- case time_method::explicit_euler:
- {
- explicit_euler(period, time_step, method);
- break;
- }
- }
- }
- std::vector<vector_type> quadratic(const std::vector<object_type *>& objects) const;
- std::vector<vector_type> finit_element(const std::vector<object_type *>& objects) const;
- void explicit_euler(T period, T time_step,
- std::function<std::vector<vector_type>(const model<T, dim>&, const std::vector<object_type *>&)> method);
- method(*this, objects);
Add Comment
Please, Sign In to add comment