FEDEM Solver  R8.0
Source code of the dynamics solver
FFaOpUtils.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
14 #ifndef FFA_OP_UTILS_H
15 #define FFA_OP_UTILS_H
16 
17 #include <string>
18 
24 
25 
26 namespace
27 {
29  template <class ToType, class FromType>
30  bool tryConverting(FFaOperation<ToType>*& to, FFaOperationBase* from,
31  const std::string& operationName, const FromType&)
32  {
33  FFaOperation<FromType>* fp = dynamic_cast<FFaOperation<FromType>*>(from);
34  if (!fp) return false;
35 
36  to = new FFaUnaryOp<ToType,FromType>(fp,operationName);
37  return true;
38  }
39 }
40 
41 
42 namespace FFaOpUtils
43 {
44  typedef std::vector<double> DoubleVec;
45 
47  template <class RetType>
49  FFaOperationBase* from,
50  const std::string& operationName)
51  {
52  if (from)
53  {
54  if (tryConverting(to,from,operationName,double())) return true;
55  if (tryConverting(to,from,operationName,float())) return true;
56  if (tryConverting(to,from,operationName,int())) return true;
57  if (tryConverting(to,from,operationName,DoubleVec())) return true;
58  if (tryConverting(to,from,operationName,FaVec3())) return true;
59  if (tryConverting(to,from,operationName,FFaTensor3())) return true;
60  if (tryConverting(to,from,operationName,FFaTensor2())) return true;
61  if (tryConverting(to,from,operationName,FFaTensor1())) return true;
62  if (tryConverting(to,from,operationName,FaMat34())) return true;
63  if (tryConverting(to,from,operationName,FaMat33())) return true;
64  from->unref(); // Invalid convertion, erase the object to avoid leakage
65  }
66  std::cerr <<" *** FFaOpUtils::getUnaryConvertOp: Invalid operation name \""
67  << operationName <<"\""<< std::endl;
68  to = NULL;
69  return false;
70  }
71 
73  std::vector<std::string> findOpers(const std::string& varType,
74  bool silence = false);
75 
77  inline bool hasOpers(const std::string& varType)
78  {
79  return !findOpers(varType,true).empty();
80  }
81 
83  std::string getDefaultOper(const std::string& varType,
84  bool silence = false);
85 }
86 
87 #endif
Classes that make up the core of a operation/transformation system.
Base class for all operations.
Definition: FFaOperation.H:38
void unref()
Decrements the reference counter, and deletes *this if zero.
Definition: FFaOperation.H:49
The base class used as argument in other operations.
Definition: FFaOperation.H:76
Definition: FFaTensor1.H:24
Definition: FFaTensor2.H:27
Definition: FFaTensor3.H:27
A class for scalar operations.
Definition: FFaOperation.H:212
Definition: FFaMat33.H:15
Definition: FFaMat34.H:16
Class for point vectors in 3D space.
Definition: FFaVec3.H:40
Utilities for accessing unary operations.
Definition: FFaOpUtils.H:43
std::string getDefaultOper(const std::string &varType, bool silence=false)
Returns default operation name for a given variable type.
Definition: FFaOpUtils.C:52
std::vector< std::string > findOpers(const std::string &varType, bool silence=false)
Returns valid operation names for a given variable type.
Definition: FFaOpUtils.C:18
bool hasOpers(const std::string &varType)
Checks if given variable type has any operation defined.
Definition: FFaOpUtils.H:77
std::vector< double > DoubleVec
Convenience type definition.
Definition: FFaOpUtils.H:44
bool getUnaryConvertOp(FFaOperation< RetType > *&to, FFaOperationBase *from, const std::string &operationName)
Converts an operation based on name and return type.
Definition: FFaOpUtils.H:48