blob: d92baea0829923bcce294549be38afcdf6569a82 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2000-2019 Ericsson Telecom AB //
// //
// All rights reserved. This program and the accompanying materials //
// are made available under the terms of the Eclipse Public License v2.0 //
// which accompanies this distribution, and is available at //
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html //
// //
///////////////////////////////////////////////////////////////////////////////
#include "EPTF_CLL_DataSource_Functions.hh"
#include <strings.h>
#include <regex.h>
#include <stdlib.h>
INTEGER EPTF__CLL__DataSource__Functions::f__EPTF__DataSource__compare(
const EPTF__CLL__DataSource__Definitions::EPTF__DataSource__Param& pl__par1,
const EPTF__CLL__DataSource__Definitions::EPTF__DataSource__Param& pl__par2
) {
return strcmp((const char*)pl__par1.paramName(),(const char*)pl__par2.paramName());
}
INTEGER EPTF__CLL__DataSource__Functions::f__EPTF__DataSource__str2float(
const CHARSTRING& pl__str,
FLOAT& pl__float
) {
const char* posix_str = "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$";
regex_t posix_regexp;
int ret_val=regcomp(&posix_regexp, posix_str, REG_EXTENDED);
if(ret_val!=0) {
char err[512];
regerror(ret_val, &posix_regexp, err, sizeof(err));
regfree(&posix_regexp);
TTCN_warning("Function regcomp() failed for string "
"\"%s\": %s", posix_str, err);
return -1;
}
int result = regexec(&posix_regexp, (const char*)pl__str, 0, NULL, 0);
regfree(&posix_regexp);
if(result == REG_NOMATCH) {
return -2;
}
pl__float = atof((const char*)pl__str);
return 0;
}
///////////////////////////////////////////////////////////
// Implementation of the external function f_EPTF_DataSourceClient_downcast.
///////////////////////////////////////////////////////////
EPTF__CLL__DataSource__Definitions::EPTF__DataSourceClient__CT
EPTF__CLL__DataSource__Definitions::f__EPTF__DataSourceClient__downcast(const INTEGER& pl__dataSourceClientCompRef) {
return EPTF__CLL__DataSource__Definitions::EPTF__DataSourceClient__CT(pl__dataSourceClientCompRef);
}