Skip to content

Commit

Permalink
Fix compilation error under c++11 and switch to c++11
Browse files Browse the repository at this point in the history
Fix compilation error under c++11 due to namespace clash
  • Loading branch information
bastien-roucaries committed Dec 11, 2013
1 parent 2b48407 commit 379559d
Show file tree
Hide file tree
Showing 54 changed files with 570 additions and 424 deletions.
1 change: 1 addition & 0 deletions qucs-core/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test "x$prefix" = xNONE && prefix="/usr/local"

dnl Checks for programs.
AC_PROG_CXX
AX_CXX_COMPILE_STDCXX_11
AC_PROG_CC
AC_CHECK_TOOL(AR, ar, :)

Expand Down
133 changes: 133 additions & 0 deletions qucs-core/m4/ax_cxx_compile_stdcxx_11.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# ============================================================================
# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
# ============================================================================
#
# SYNOPSIS
#
# AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
#
# DESCRIPTION
#
# Check for baseline language coverage in the compiler for the C++11
# standard; if necessary, add switches to CXXFLAGS to enable support.
#
# The first argument, if specified, indicates whether you insist on an
# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
# -std=c++11). If neither is specified, you get whatever works, with
# preference for an extended mode.
#
# The second argument, if specified 'mandatory' or if left unspecified,
# indicates that baseline C++11 support is required and that the macro
# should error out if no mode with that support is found. If specified
# 'optional', then configuration proceeds regardless, after defining
# HAVE_CXX11 if and only if a supporting mode is found.
#
# LICENSE
#
# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
# Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
# Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 3

m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [
template <typename T>
struct check
{
static_assert(sizeof(int) <= sizeof(T), "not big enough");
};
typedef check<check<bool>> right_angle_brackets;
int a;
decltype(a) b;
typedef check<int> check_type;
check_type c;
check_type&& cr = static_cast<check_type&&>(c);
auto d = a;
])

AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
m4_if([$1], [], [],
[$1], [ext], [],
[$1], [noext], [],
[m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
[$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
[$2], [optional], [ax_cxx_compile_cxx11_required=false],
[m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])dnl
AC_LANG_PUSH([C++])dnl
ac_success=no
AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
ax_cv_cxx_compile_cxx11,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
[ax_cv_cxx_compile_cxx11=yes],
[ax_cv_cxx_compile_cxx11=no])])
if test x$ax_cv_cxx_compile_cxx11 = xyes; then
ac_success=yes
fi
m4_if([$1], [noext], [], [dnl
if test x$ac_success = xno; then
for switch in -std=gnu++11 -std=gnu++0x; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
$cachevar,
[ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXXFLAGS="$ac_save_CXXFLAGS"])
if eval test x\$$cachevar = xyes; then
CXXFLAGS="$CXXFLAGS $switch"
ac_success=yes
break
fi
done
fi])
m4_if([$1], [ext], [], [dnl
if test x$ac_success = xno; then
for switch in -std=c++11 -std=c++0x; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
$cachevar,
[ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXXFLAGS="$ac_save_CXXFLAGS"])
if eval test x\$$cachevar = xyes; then
CXXFLAGS="$CXXFLAGS $switch"
ac_success=yes
break
fi
done
fi])
AC_LANG_POP([C++])
if test x$ax_cxx_compile_cxx11_required = xtrue; then
if test x$ac_success = xno; then
AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
fi
else
if test x$ac_success = xno; then
HAVE_CXX11=0
AC_MSG_NOTICE([No compiler with C++11 support was found])
else
HAVE_CXX11=1
AC_DEFINE(HAVE_CXX11,1,
[define if the compiler supports basic C++11 syntax])
fi
AC_SUBST(HAVE_CXX11)
fi
])
6 changes: 3 additions & 3 deletions qucs-core/src/acsolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ void acsolver::init (void) {
/* This function saves the results of a single solve() functionality
(for the given frequency) into the output dataset. */
void acsolver::saveAllResults (nr_double_t freq) {
vector * f;
::vector * f;
// add current frequency to the dependency of the output dataset
if ((f = data->findDependency ("acfrequency")) == NULL) {
f = new vector ("acfrequency");
f = new ::vector ("acfrequency");
data->addDependency (f);
}
if (runs == 1) f->add (freq);
Expand All @@ -156,7 +156,7 @@ void acsolver::saveAllResults (nr_double_t freq) {

/* The function computes the final noise results and puts them into
the output dataset. */
void acsolver::saveNoiseResults (vector * f) {
void acsolver::saveNoiseResults (::vector * f) {
int N = countNodes ();
int M = countVoltageSources ();
for (int r = 0; r < N + M; r++) {
Expand Down
2 changes: 1 addition & 1 deletion qucs-core/src/acsolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class acsolver : public nasolver<nr_complex_t>
static void calc (acsolver *);
void init (void);
void saveAllResults (nr_double_t);
void saveNoiseResults (vector *);
void saveNoiseResults (::vector *);

private:
sweep * swp;
Expand Down
2 changes: 1 addition & 1 deletion qucs-core/src/analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class analysis : public object
* Saves the given variable into the dataset associated with the
* analysis. Creates the dataset vector if necessary.
*/
void saveVariable (const char *, nr_complex_t, vector *);
void saveVariable (const char *, nr_complex_t, ::vector *);

/*! \fn getProgress
* \brief get
Expand Down
24 changes: 12 additions & 12 deletions qucs-core/src/check_citi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct citi_package_t * citi_root = NULL;
/* Returns the number of vectors in a package. */
static int citi_count_vectors (struct citi_package_t * p) {
int i = 0;
for (vector * v = p->data; v != NULL; v = (vector *) v->getNext ()) i++;
for (::vector * v = p->data; v != NULL; v = (::vector *) v->getNext ()) i++;
return i;
}

Expand All @@ -63,9 +63,9 @@ static int citi_count_variables (struct citi_package_t * p) {
}

/* Returns the n-th vector in the package. */
static vector * citi_get_vector (struct citi_package_t * p, int n) {
vector * v = p->data;
for (int i = 0; v != NULL; v = (vector *) v->getNext (), i++) {
static ::vector * citi_get_vector (struct citi_package_t * p, int n) {
::vector * v = p->data;
for (int i = 0; v != NULL; v = (::vector *) v->getNext (), i++) {
if (i == n) return v;
}
return NULL;
Expand All @@ -87,11 +87,11 @@ static char * citi_get_package (struct citi_package_t * p) {
}

/* Create a valid vector for the dataset. */
static vector * citi_create_vector (struct citi_package_t * p, int i,
static ::vector * citi_create_vector (struct citi_package_t * p, int i,
char * n, char * type) {
vector * vec;
::vector * vec;
vec = citi_get_vector (p, i); // fetch vector
vec = new vector (*vec); // copy vector
vec = new ::vector (*vec); // copy vector
vec->reverse (); // reverse vector

// convert data if necessary
Expand Down Expand Up @@ -123,14 +123,14 @@ static int citi_vector_length (strlist deps) {
return 0;
// calculate length of resulting dependent variable
for (int i = 0; i < deps.length(); i++) {
vector * v = citi_result->findDependency (deps.get (i));
::vector * v = citi_result->findDependency (deps.get (i));
if (v != NULL) n *= v->getSize ();
}
return n;
}

/* Checks length of variable vectors. */
static int citi_check_dep_length (vector * v, strlist deps, char * package) {
static int citi_check_dep_length (::vector * v, strlist deps, char * package) {
int rlength = v->getSize ();
int dlength = citi_vector_length (deps);
if (rlength != dlength) {
Expand All @@ -156,10 +156,10 @@ void citi_finalize (void) {
hn = h->next;
free (h);
}
vector * v, * vn;
::vector * v, * vn;
/* go through each vector */
for (v = p->data; v != NULL; v = vn) {
vn = (vector *) v->getNext ();
vn = (::vector *) v->getNext ();
delete v;
}
pn = p->next;
Expand Down Expand Up @@ -209,7 +209,7 @@ int citi_check (void) {

/* go through each header */
for (h = p->head; h != NULL; h = h->next) {
vector * v;
::vector * v;
if (h->var != NULL) {
char txt[256];
if (h->i1 >= 0) {
Expand Down
2 changes: 1 addition & 1 deletion qucs-core/src/check_citi.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct citi_header_t {

struct citi_package_t {
struct citi_header_t * head;
vector * data;
::vector * data;
struct citi_package_t * next;
};

Expand Down
18 changes: 9 additions & 9 deletions qucs-core/src/check_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
#include "check_csv.h"

strlist * csv_header = NULL;
vector * csv_vector = NULL;
::vector * csv_vector = NULL;
dataset * csv_result = NULL;

/* Removes temporary data items from memory if necessary. */
static void csv_finalize (void) {
vector * root, * next;
::vector * root, * next;
for (root = csv_vector; root != NULL; root = next) {
next = (vector *) root->getNext ();
next = (::vector *) root->getNext ();
delete root;
}
csv_vector = NULL;
Expand All @@ -76,15 +76,15 @@ static void csv_validate_str (char * n) {

/* Creates dataset from CSV vectors. */
static void csv_create_dataset (int len) {
vector * dep, * indep, * v;
::vector * dep, * indep, * v;
char * n, depn[256];
strlist * s;

// create dataset
csv_result = new dataset ();

// add dependency vector
indep = new vector ();
indep = new ::vector ();
csv_result->appendDependency (indep);
s = new strlist ();
n = csv_header ? csv_header->get (0) : (char *) "x";
Expand All @@ -94,7 +94,7 @@ static void csv_create_dataset (int len) {

// create variable vector(s)
for (int i = 1; i < len; i++) {
v = new vector ();
v = new ::vector ();
n = csv_header ? csv_header->get (i) : NULL;
if (n == NULL) {
sprintf (depn, "y%d", i);
Expand All @@ -107,12 +107,12 @@ static void csv_create_dataset (int len) {
}

// fill all vectors in dataset
for (v = csv_vector; v != NULL; v = (vector *) v->getNext ()) {
for (v = csv_vector; v != NULL; v = (::vector *) v->getNext ()) {
dep = csv_result->getVariables ();
int l;
for (l = 0; l < v->getSize () - 1; l++) {
dep->add (v->get (l));
dep = (vector *) dep->getNext ();
dep = (::vector *) dep->getNext ();
}
indep->add (v->get (l));
}
Expand All @@ -135,7 +135,7 @@ int csv_check (void) {
// data lines available
else {
// check number of columns in each data line
for (vector * v = csv_vector; v != NULL; v = (vector *) v->getNext ()) {
for (::vector * v = csv_vector; v != NULL; v = (::vector *) v->getNext ()) {
if (len == -1) len = v->getSize ();
else {
if (v->getSize () != len) {
Expand Down
2 changes: 1 addition & 1 deletion qucs-core/src/check_csv.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class vector;
class strlist;

extern dataset * csv_result;
extern vector * csv_vector;
extern ::vector * csv_vector;
extern strlist * csv_header;

/* Externalize variables used by the scanner and parser. */
Expand Down
2 changes: 1 addition & 1 deletion qucs-core/src/check_netlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ static variable * checker_add_variable (environment * env,
c->d = 0.0; // initialize the variable
break;
case TAG_VECTOR:
c->v = new vector ();
c->v = new ::vector ();
break;
}
v->setConstant (c);
Expand Down
Loading

0 comments on commit 379559d

Please sign in to comment.