Skip to content

Commit

Permalink
libxorp/ustl: Change code to work with ustl limitations.
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Greear <greearb@candelatech.com>
  • Loading branch information
greearb committed Jun 14, 2010
1 parent 0d96a1b commit 91d9552
Show file tree
Hide file tree
Showing 31 changed files with 193 additions and 95 deletions.
6 changes: 6 additions & 0 deletions xorp/libxorp/asnum.hh
Expand Up @@ -246,6 +246,12 @@ public:
private:
uint32_t _as; // The value of the AS number

#ifdef XORP_USE_USTL
public:
AsNum() { };
#else
AsNum(); // forbidden
#endif

};
#endif // __LIBXORP_ASNUM_HH__
2 changes: 1 addition & 1 deletion xorp/libxorp/asyncio.cc
Expand Up @@ -303,7 +303,7 @@ template <typename T, typename U>
static void
iov_place(T*& iov_base, U& iov_len, uint8_t* data, size_t data_len)
{
static_assert(sizeof(T*) == sizeof(uint8_t*));
x_static_assert(sizeof(T*) == sizeof(uint8_t*));
iov_base = reinterpret_cast<T*>(data);
iov_len = data_len;
}
Expand Down
2 changes: 0 additions & 2 deletions xorp/libxorp/callback.cc
Expand Up @@ -41,8 +41,6 @@
#include "libxorp/timeval.hh"
#include "libxorp/timer.hh"

#include <stack>


/**
* Maximum callback dispatch duration.
Expand Down
6 changes: 3 additions & 3 deletions xorp/libxorp/exceptions.cc
Expand Up @@ -20,15 +20,15 @@



#include "exceptions.hh"
#include <stdarg.h>
#include <stdio.h>

#include <exception>
#ifndef XORP_USE_USTL
#include <typeinfo>
#endif


#include "exceptions.hh"

XorpException::XorpException(const char* init_what,
const char* file,
size_t line)
Expand Down
9 changes: 8 additions & 1 deletion xorp/libxorp/exceptions.hh
Expand Up @@ -25,10 +25,17 @@
#ifndef __LIBXORP_EXCEPTIONS_HH__
#define __LIBXORP_EXCEPTIONS_HH__

#include "xorp.h"

#ifdef XORP_USE_USTL
#include <ustl/uexception.h>
using namespace std;
#else
#include <exception>
#endif

#include <stdarg.h>

#include "xorp.h"
#include "libxorp/c_format.hh"

/**
Expand Down
2 changes: 1 addition & 1 deletion xorp/libxorp/heap.hh
Expand Up @@ -27,7 +27,7 @@
#ifndef __LIBXORP_HEAP_HH__
#define __LIBXORP_HEAP_HH__

#include <memory>


#include <stdio.h>
#ifdef HAVE_STDLIB_H
Expand Down
2 changes: 1 addition & 1 deletion xorp/libxorp/ipv4.hh
Expand Up @@ -507,7 +507,7 @@ public:
* @return address size in number of octets.
*/
static size_t addr_bytelen() {
static_assert(sizeof(IPv4) == sizeof(uint32_t));
x_static_assert(sizeof(IPv4) == sizeof(uint32_t));
return sizeof(IPv4);
}

Expand Down
6 changes: 3 additions & 3 deletions xorp/libxorp/ipv6.cc
Expand Up @@ -223,7 +223,7 @@ IPv6
IPv6::operator<<(uint32_t ls) const
{
uint32_t tmp_addr[4];
static_assert(sizeof(_addr) == sizeof(tmp_addr));
x_static_assert(sizeof(_addr) == sizeof(tmp_addr));

// Shift the words, and at the same time convert them into host-order
switch (ls / 32) {
Expand Down Expand Up @@ -278,7 +278,7 @@ IPv6
IPv6::operator>>(uint32_t rs) const
{
uint32_t tmp_addr[4];
static_assert(sizeof(_addr) == sizeof(tmp_addr));
x_static_assert(sizeof(_addr) == sizeof(tmp_addr));

// Shift the words, and at the same time convert them into host-order
switch (rs / 32) {
Expand Down Expand Up @@ -333,7 +333,7 @@ bool
IPv6::operator<(const IPv6& other) const
{
int i;
static_assert(sizeof(_addr) == 16);
x_static_assert(sizeof(_addr) == 16);

for (i = 0; i < 3; i++) { // XXX: Loop ends intentionally at 3 not 4
if (_addr[i] != other._addr[i])
Expand Down
2 changes: 1 addition & 1 deletion xorp/libxorp/ipv6.hh
Expand Up @@ -460,7 +460,7 @@ public:
* @return address size in number of octets.
*/
static size_t addr_bytelen() {
static_assert(sizeof(IPv6) == 4 * sizeof(uint32_t));
x_static_assert(sizeof(IPv6) == 4 * sizeof(uint32_t));
return sizeof(IPv6);
}

Expand Down
10 changes: 5 additions & 5 deletions xorp/libxorp/ipvx.cc
Expand Up @@ -70,8 +70,8 @@ IPvX::IPvX(int family, const uint8_t *from_uint8) throw (InvalidFamily)

IPvX::IPvX(const IPv4& ipv4)
{
static_assert(sizeof(_addr) >= sizeof(IPv4));
static_assert(sizeof(IPv4) == 4);
x_static_assert(sizeof(_addr) >= sizeof(IPv4));
x_static_assert(sizeof(IPv4) == 4);

_af = AF_INET;
memset(_addr, 0, sizeof(_addr));
Expand All @@ -80,8 +80,8 @@ IPvX::IPvX(const IPv4& ipv4)

IPvX::IPvX(const IPv6& ipv6)
{
static_assert(sizeof(_addr) >= sizeof(IPv6));
static_assert(sizeof(IPv6) == 16);
x_static_assert(sizeof(_addr) >= sizeof(IPv6));
x_static_assert(sizeof(IPv6) == 16);

_af = AF_INET6;
memcpy(_addr, &ipv6, 16);
Expand Down Expand Up @@ -198,7 +198,7 @@ IPvX::operator>>(uint32_t right_shift) const
bool
IPvX::operator<(const IPvX& other) const
{
static_assert(sizeof(_addr) == 16);
x_static_assert(sizeof(_addr) == 16);
int i;

for (i = 0; i < 3; i++) { // Loop ends intentionally at 3 not 4.
Expand Down
4 changes: 3 additions & 1 deletion xorp/libxorp/ipvxnet.hh
Expand Up @@ -84,7 +84,9 @@ public:
*/
explicit IPvXNet(int family) throw (InvalidFamily)
: BaseIPvXNet(IPvX::ZERO(family), 0) {}

#ifdef XORP_USE_USTL
IPvXNet() : BaseIPvXNet(IPvX::ZERO(AF_INET), 0) {}
#endif
/**
* Copy constructor for BaseIPvXNet subnet address
*
Expand Down
14 changes: 13 additions & 1 deletion xorp/libxorp/nexthop.hh
Expand Up @@ -108,6 +108,10 @@ public:
* to initialize nexthop.
*/
IPNextHop(const A &from_ipaddr);

#ifdef XORP_USE_USTL
IPNextHop() { }
#endif

/**
* Get the address of the nexthop.
Expand Down Expand Up @@ -141,7 +145,11 @@ public:
* to initialize nexthop.
*/
IPPeerNextHop(const A &from_addr);


#ifdef XORP_USE_USTL
IPPeerNextHop() { }
#endif

/**
* Get the type of the nexthop.
*
Expand Down Expand Up @@ -230,6 +238,10 @@ public:
* to initialize nexthop.
*/
IPExternalNextHop(const A &from_addr);

#ifdef XORP_USE_USTL
IPExternalNextHop() { }
#endif

/**
* Get the type of the nexthop.
Expand Down
1 change: 0 additions & 1 deletion xorp/libxorp/popen.hh
Expand Up @@ -24,7 +24,6 @@
#ifndef __LIBXORP_POPEN_HH__
#define __LIBXORP_POPEN_HH__

#include<list>

pid_t popen2(const string& command, const list<string>& arguments,
FILE *& outstream, FILE *& errstream,
Expand Down
29 changes: 19 additions & 10 deletions xorp/libxorp/profile.cc
Expand Up @@ -36,25 +36,24 @@ Profile::Profile()
{
}

inline
void
zap(pair<const string, ref_ptr<Profile::ProfileState> >& p)
{
p.second->zap();
}

Profile::~Profile()
{
for_each(_profiles.begin(), _profiles.end(), ptr_fun(zap));
while (!_profiles.empty()) {
profiles::iterator i = _profiles.begin();
i->second->zap();
_profiles.erase(i);
}
}

void
Profile::create(const string& pname, const string& comment)
throw(PVariableExists)
{
// Catch initialization problems.
#ifndef XORP_USE_USTL
if (_profiles.count(pname))
xorp_throw(PVariableExists, pname.c_str());
#endif

ProfileState *p = new ProfileState(comment, false, false, new logentries);
_profiles[pname] = ref_ptr<ProfileState>(p);
Expand Down Expand Up @@ -205,6 +204,7 @@ Profile::clear(const string& pname) throw(PVariableUnknown,PVariableLocked)
i->second->logptr()->clear();
}

#if 0
class List: public unary_function<pair<const string,
ref_ptr<Profile::ProfileState> >,
void> {
Expand All @@ -226,11 +226,20 @@ class List: public unary_function<pair<const string,
private:
string _result;
};
#endif

string
Profile::list() const
Profile::get_list() const
{
return for_each(_profiles.begin(), _profiles.end(), List()).result();
ostringstream oss;
profiles::const_iterator i = _profiles.begin();
while (i != _profiles.end()) {
oss << i->first << "\t" << i->second->size() << "\t"
<< (i->second->enabled() ? "enabled" : "disabled")
<< "\t" << i->second->comment() << "\n";
i++;
}
return oss.str();
}

// simple profiler
Expand Down
6 changes: 3 additions & 3 deletions xorp/libxorp/profile.hh
Expand Up @@ -35,7 +35,7 @@




#include "xorp.h"
#include "timeval.hh"
#include "exceptions.hh"
#include "ref_ptr.hh"
Expand Down Expand Up @@ -103,7 +103,7 @@ class ProfileLogEntry {
*/
class Profile {
public:
typedef std::list<ProfileLogEntry> logentries; // Profiling info
typedef list<ProfileLogEntry> logentries; // Profiling info

class ProfileState {
public:
Expand Down Expand Up @@ -215,7 +215,7 @@ class Profile {
* @return A newline separated list of profiling variables along
* with the associated comments.
*/
string list() const;
string get_list() const;

private:
int _profile_cnt; // Number of variables that are enabled.
Expand Down
2 changes: 1 addition & 1 deletion xorp/libxorp/range.hh
Expand Up @@ -24,7 +24,7 @@
#ifndef __LIBXORP_RANGE_HH__
#define __LIBXORP_RANGE_HH__

#include <sstream>


class IPv4;
class IPv6;
Expand Down
23 changes: 23 additions & 0 deletions xorp/libxorp/ref_ptr.hh
Expand Up @@ -194,11 +194,34 @@ public:
*/
_Tp* get() const { return _M_ptr; }

#ifdef XORP_USE_USTL

// Compare pointed-to items.
bool operator==(const ref_ptr& rp) const {
if (_M_ptr == rp._M_ptr)
return true;
if (_M_ptr && rp._M_ptr)
return (*_M_ptr == *rp._M_ptr);
return false;
}

// Compare pointed-to items.
bool operator< (const ref_ptr& b) {
if (_M_ptr && b._M_ptr)
return (*_M_ptr < *b._M_ptr);
if (_M_ptr == b._M_ptr)
return false;
if (b._M_ptr)
return true;
}

#else
/**
* Equality Operator
* @return true if reference pointers refer to same object.
*/
bool operator==(const ref_ptr& rp) const { return _M_ptr == rp._M_ptr; }
#endif

/**
* Check if reference pointer refers to an object or whether it has
Expand Down
2 changes: 1 addition & 1 deletion xorp/libxorp/safe_callback_obj.cc
Expand Up @@ -61,7 +61,7 @@ SafeCallbackBase::valid() const

CallbackSafeObject::~CallbackSafeObject()
{
std::vector<SafeCallbackBase*>::iterator i = _cbs.begin();
vector<SafeCallbackBase*>::iterator i = _cbs.begin();
while (_cbs.empty() == false) {
SafeCallbackBase* scb = *i;
if (scb == 0) {
Expand Down
5 changes: 2 additions & 3 deletions xorp/libxorp/safe_callback_obj.hh
Expand Up @@ -28,7 +28,6 @@

#include "xorp.h"


class SafeCallbackBase;

/**
Expand Down Expand Up @@ -56,7 +55,7 @@ public:
void unref_cb(SafeCallbackBase* scb);

protected:
std::vector<SafeCallbackBase*> _cbs;
vector<SafeCallbackBase*> _cbs;
};

/**
Expand Down Expand Up @@ -108,7 +107,7 @@ CallbackSafeObject::ref_cb(SafeCallbackBase* scb)
inline void
CallbackSafeObject::unref_cb(SafeCallbackBase* scb)
{
std::vector<SafeCallbackBase*>::iterator i =
vector<SafeCallbackBase*>::iterator i =
find(_cbs.begin(), _cbs.end(), scb);
if (i != _cbs.end())
_cbs.erase(i);
Expand Down
2 changes: 1 addition & 1 deletion xorp/libxorp/selector.cc
Expand Up @@ -241,7 +241,7 @@ SelectorList::SelectorList(ClockBase *clock)
_selector_entries(1024),
_maxfd(0), _descriptor_count(0), _is_debug(false)
{
static_assert(SEL_RD == (1 << SEL_RD_IDX) && SEL_WR == (1 << SEL_WR_IDX)
x_static_assert(SEL_RD == (1 << SEL_RD_IDX) && SEL_WR == (1 << SEL_WR_IDX)
&& SEL_EX == (1 << SEL_EX_IDX) && SEL_MAX_IDX == 3);
for (int i = 0; i < SEL_MAX_IDX; i++)
FD_ZERO(&_fds[i]);
Expand Down
2 changes: 1 addition & 1 deletion xorp/libxorp/selector.hh
Expand Up @@ -236,7 +236,7 @@ private:
private:
enum {
// correspond to SelectorMask; correspondence checked with
// static_assert
// x_static_assert
SEL_RD_IDX = 0,
SEL_WR_IDX = 1,
SEL_EX_IDX = 2,
Expand Down

0 comments on commit 91d9552

Please sign in to comment.