Use explicit template instantiation for mjXUtil::ReadAttr.

PiperOrigin-RevId: 451481936
Change-Id: Ib26e41823606e612f017db0f606983262713066e
This commit is contained in:
Saran Tunyasuvunakool
2022-05-27 14:34:30 -07:00
committed by Copybara-Service
parent f3453cf87f
commit 6faf1d93de
2 changed files with 11 additions and 51 deletions
+10 -30
View File
@@ -19,7 +19,6 @@
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>
#include <vector>
@@ -551,8 +550,8 @@ string mjXUtil::FindValue(const mjMap* map, int mapsz, int value) {
// the content is returned in "text", the numeric data in "data"
// return true if attribute found, false if not found and not required
template<typename T>
int mjXUtil::ReadAttrCpp(XMLElement* elem, const char* attr, const int len,
T* data, string& text, bool required, bool exact) {
int mjXUtil::ReadAttr(XMLElement* elem, const char* attr, const int len,
T* data, string& text, bool required, bool exact) {
const char* pstr = elem->Attribute(attr);
// check if attribute exists
@@ -596,36 +595,17 @@ int mjXUtil::ReadAttrCpp(XMLElement* elem, const char* attr, const int len,
return i;
}
template int mjXUtil::ReadAttr(XMLElement* elem, const char* attr, const int len,
double* data, string& text, bool required, bool exact);
template int mjXUtil::ReadAttr(XMLElement* elem, const char* attr, const int len,
float* data, string& text, bool required, bool exact);
int mjXUtil::ReadAttr(XMLElement* elem, const char* attr, const int len,
double* data, string& text, bool required, bool exact) {
return ReadAttrCpp(elem, attr, len, data, text, required, exact);
}
template int mjXUtil::ReadAttr(XMLElement* elem, const char* attr, const int len,
int* data, string& text, bool required, bool exact);
// float version
int mjXUtil::ReadAttr(XMLElement* elem, const char* attr, const int len,
float* data, string& text, bool required, bool exact) {
return ReadAttrCpp(elem, attr, len, data, text, required, exact);
}
// int version
int mjXUtil::ReadAttr(XMLElement* elem, const char* attr, const int len,
int* data, string& text, bool required, bool exact) {
return ReadAttrCpp(elem, attr, len, data, text, required, exact);
}
// byte version
int mjXUtil::ReadAttr(XMLElement* elem, const char* attr, const int len,
mjtByte* data, string& text, bool required, bool exact) {
return ReadAttrCpp(elem, attr, len, data, text, required, exact);
}
template int mjXUtil::ReadAttr(XMLElement* elem, const char* attr, const int len,
mjtByte* data, string& text, bool required, bool exact);
+1 -21
View File
@@ -100,28 +100,8 @@ class mjXUtil {
// read any type from attribute, return number read
template<typename T>
static int ReadAttrCpp(tinyxml2::XMLElement* elem, const char* attr, const int len,
T* data, std::string& text,
bool required = false, bool exact = true);
// read DOUBLE array from attribute, return number read
static int ReadAttr(tinyxml2::XMLElement* elem, const char* attr, const int len,
double* data, std::string& text,
bool required = false, bool exact = true);
// read FLOAT array from attribute, return number read
static int ReadAttr(tinyxml2::XMLElement* elem, const char* attr, const int len,
float* data, std::string& text,
bool required = false, bool exact = true);
// read INT array from attribute, return number read
static int ReadAttr(tinyxml2::XMLElement* elem, const char* attr, const int len,
int* data, std::string& text,
bool required = false, bool exact = true);
// read BYTE array from attribute, return number read
static int ReadAttr(tinyxml2::XMLElement* elem, const char* attr, const int len,
mjtByte* data, std::string& text,
T* data, std::string& text,
bool required = false, bool exact = true);
// read DOUBLE array into C++ vector, return number read