Fix standalone build. Refactor ptypes.h. (nw)

This commit is contained in:
couriersud 2016-06-07 19:31:59 +02:00
parent 62ed8d252e
commit b3f6072cfd
10 changed files with 155 additions and 136 deletions

View File

@ -14,7 +14,7 @@ SRC = ..
#-fuse-ld=gold -Wpedantic -march=native -march=native
# LTO = -flto=4 -fuse-linker-plugin -flto-partition=balanced -Wodr
LTO = -flto=4 -fuse-linker-plugin -flto-partition=balanced -Wodr
CDEFS = -DPSTANDALONE=1 -DPTR64=1
#-Werror
@ -49,11 +49,12 @@ OBJS = $(POBJS) $(NLOBJS)
POBJS := \
$(POBJ)/pstring.o \
$(POBJ)/palloc.o \
$(POBJ)/pdynlib.o \
$(POBJ)/pfmtlog.o \
$(POBJ)/pparser.o \
$(POBJ)/pstate.o \
$(POBJ)/pstream.o \
$(POBJ)/pfmtlog.o \
$(POBJ)/pdynlib.o \
$(POBJ)/putil.o \
NLOBJS := \
$(NLOBJ)/nl_base.o \

View File

@ -5,6 +5,8 @@
*
*/
#include <cstring>
#include "solver/nld_matrix_solver.h"
#include "solver/nld_solver.h"

View File

@ -10,6 +10,7 @@
#include "nl_factory.h"
#include "nl_setup.h"
#include "plib/putil.h"
namespace netlist
{

View File

@ -13,6 +13,7 @@
#include "nl_config.h"
#include "plib/plists.h"
#include "plib/putil.h"
#include "nl_base.h"
#define NETLIB_DEVICE_IMPL(chip) factory_creator_ptr_t decl_ ## chip = factory_creator_t< NETLIB_NAME(chip) >;

View File

@ -190,75 +190,6 @@ public:
LC *m_head;
};
// ----------------------------------------------------------------------------------------
// string list
// ----------------------------------------------------------------------------------------
class pstring_vector_t : public pvector_t<pstring>
{
public:
pstring_vector_t() : pvector_t<pstring>() { }
pstring_vector_t(const pstring &str, const pstring &onstr, bool ignore_empty = false)
: pvector_t<pstring>()
{
int p = 0;
int pn;
pn = str.find(onstr, p);
while (pn>=0)
{
pstring t = str.substr(p, pn - p);
if (!ignore_empty || t.len() != 0)
this->push_back(t);
p = pn + onstr.len();
pn = str.find(onstr, p);
}
if (p < (int) str.len())
{
pstring t = str.substr(p);
if (!ignore_empty || t.len() != 0)
this->push_back(t);
}
}
pstring_vector_t(const pstring &str, const pstring_vector_t &onstrl)
: pvector_t<pstring>()
{
pstring col = "";
unsigned i = 0;
while (i<str.blen())
{
int p = -1;
for (std::size_t j=0; j < onstrl.size(); j++)
{
if (std::memcmp(onstrl[j].cstr(), &(str.cstr()[i]), onstrl[j].blen())==0)
{
p = j;
break;
}
}
if (p>=0)
{
if (col != "")
this->push_back(col);
col = "";
this->push_back(onstrl[p]);
i += onstrl[p].blen();
}
else
{
pstring::traits::code_t c = pstring::traits::code(str.cstr() + i);
col += c;
i+=pstring::traits::codelen(c);
}
}
if (col != "")
this->push_back(col);
}
};
// ----------------------------------------------------------------------------------------
// hashmap list

View File

@ -14,6 +14,7 @@
#include "pstring.h"
#include "plists.h"
#include "putil.h"
namespace plib {
@ -82,7 +83,7 @@ public:
pstring operator ()() { return m_val; }
private:
pstring m_val;
pstring_vector_t m_limit;
plib::pstring_vector_t m_limit;
};
class option_bool : public option

View File

@ -11,6 +11,7 @@
#include "pconfig.h"
#include "pstring.h"
#include "plists.h"
#include "putil.h"
#include "pstream.h"
namespace plib {
@ -176,7 +177,7 @@ protected:
postream &process_i(pistream &istrm, postream &ostrm);
double expr(const pstring_vector_t &sexpr, std::size_t &start, int prio);
double expr(const plib::pstring_vector_t &sexpr, std::size_t &start, int prio);
define_t *get_define(const pstring &name);
@ -189,7 +190,7 @@ private:
pstring process_line(const pstring &line);
hashmap_t<pstring, define_t> m_defines;
pstring_vector_t m_expr_sep;
plib::pstring_vector_t m_expr_sep;
//pstringbuffer m_ret;
UINT32 m_ifflag; // 31 if levels

View File

@ -13,68 +13,16 @@
namespace plib {
//============================================================
// penum - strongly typed enumeration
//============================================================
//============================================================
// penum - strongly typed enumeration
//============================================================
struct enum_base
{
protected:
static int from_string_int(const char *str, const char *x)
struct enum_base
{
int cnt = 0;
const char *cur = str;
int lx = strlen(x);
while (*str)
{
if (*str == ',')
{
int l = str-cur;
if (l == lx)
if (strncmp(cur, x, lx) == 0)
return cnt;
}
else if (*str == ' ')
{
cur = str + 1;
cnt++;
}
str++;
}
int l = str-cur;
if (l == lx)
if (strncmp(cur, x, lx) == 0)
return cnt;
return -1;
}
static pstring nthstr(int n, const char *str)
{
char buf[64];
char *bufp = buf;
int cur = 0;
while (*str)
{
if (cur == n)
{
if (*str == ',')
{
*bufp = 0;
return pstring(buf);
}
else if (*str != ' ')
*bufp++ = *str;
}
else
{
if (*str == ',')
cur++;
}
str++;
}
*bufp = 0;
return pstring(buf);
}
};
protected:
static int from_string_int(const char *str, const char *x);
static pstring nthstr(int n, const char *str);
};
}

View File

@ -7,6 +7,7 @@
#include <initializer_list>
#include "plib/putil.h"
#include "plib/ptypes.h"
#include "plib/plists.h"
namespace plib
@ -38,4 +39,123 @@ namespace plib
return pstring(getenv(var.cstr()));
}
}
}
pstring_vector_t::pstring_vector_t(const pstring &str, const pstring &onstr, bool ignore_empty)
: pvector_t<pstring>()
{
int p = 0;
int pn;
pn = str.find(onstr, p);
while (pn>=0)
{
pstring t = str.substr(p, pn - p);
if (!ignore_empty || t.len() != 0)
this->push_back(t);
p = pn + onstr.len();
pn = str.find(onstr, p);
}
if (p < (int) str.len())
{
pstring t = str.substr(p);
if (!ignore_empty || t.len() != 0)
this->push_back(t);
}
}
pstring_vector_t::pstring_vector_t(const pstring &str, const pstring_vector_t &onstrl)
: pvector_t<pstring>()
{
pstring col = "";
unsigned i = 0;
while (i<str.blen())
{
int p = -1;
for (std::size_t j=0; j < onstrl.size(); j++)
{
if (std::memcmp(onstrl[j].cstr(), &(str.cstr()[i]), onstrl[j].blen())==0)
{
p = j;
break;
}
}
if (p>=0)
{
if (col != "")
this->push_back(col);
col = "";
this->push_back(onstrl[p]);
i += onstrl[p].blen();
}
else
{
pstring::traits::code_t c = pstring::traits::code(str.cstr() + i);
col += c;
i+=pstring::traits::codelen(c);
}
}
if (col != "")
this->push_back(col);
}
int enum_base::from_string_int(const char *str, const char *x)
{
int cnt = 0;
const char *cur = str;
int lx = strlen(x);
while (*str)
{
if (*str == ',')
{
int l = str-cur;
if (l == lx)
if (strncmp(cur, x, lx) == 0)
return cnt;
}
else if (*str == ' ')
{
cur = str + 1;
cnt++;
}
str++;
}
int l = str-cur;
if (l == lx)
if (strncmp(cur, x, lx) == 0)
return cnt;
return -1;
}
pstring enum_base::nthstr(int n, const char *str)
{
char buf[64];
char *bufp = buf;
int cur = 0;
while (*str)
{
if (cur == n)
{
if (*str == ',')
{
*bufp = 0;
return pstring(buf);
}
else if (*str != ' ')
*bufp++ = *str;
}
else
{
if (*str == ',')
cur++;
}
str++;
}
*bufp = 0;
return pstring(buf);
}
} // namespace plib

View File

@ -20,6 +20,19 @@ namespace plib
const pstring buildpath(std::initializer_list<pstring> list );
const pstring environment(const pstring &var, const pstring &default_val = "");
}
// ----------------------------------------------------------------------------------------
// string list
// ----------------------------------------------------------------------------------------
class pstring_vector_t : public pvector_t<pstring>
{
public:
pstring_vector_t() : pvector_t<pstring>() { }
pstring_vector_t(const pstring &str, const pstring &onstr, bool ignore_empty = false);
pstring_vector_t(const pstring &str, const pstring_vector_t &onstrl);
};
}
#endif /* P_UTIL_H_ */