[Click] Use STL for new element
Alan Tang
hao.tang at student.groept.be
Sun Mar 13 03:00:46 EST 2005
Dear everyone
Since I can not find documentation about how to use hashmap in click. I
used map from stl.
Strangely map from stl is okay. But when I try to compile the new
element, error from my system library came out, which I don't
understand. Here is the header file of the new element. I also added
the small program that proves my map from system library is okay.
#ifndef CLICK_SMARTQUEUE_HH
#define CLICK_SMARTQUEUE_HH
#include "../standard/notifierqueue.hh"
#include <map>
using namespace std;
CLICK_DECLS
/*
*/
class SmartQueue : public NotifierQueue
{
public:
SmartQueue();
~SmartQueue();
const char *class_name() const {return "SmartQueue";}
void *cast(const char *);
void push(int port,Packet *);
void statistics();
private:
map<unsigned,unsigned> _statistics;
};
CLICK_ENDDECLS
#endif
----------------------------------------------------------
error msg (first 20%):
g++ -w -W -Wall -fno-exceptions -fno-rtti -fpermissive -DHAVE_CONFIG_H
-I../include -I../include -I. -I.. -I/usr/src/linux/include
-INONE/click_wifi -DCLICK_LINUXMODULE -O2 -MD -c
../elements/local/smartqueue.cc
In file included from /usr/include/c++/3.3/cstring:51,
from /usr/include/c++/3.3/bits/stl_algobase.h:65,
from /usr/include/c++/3.3/bits/stl_tree.h:86,
from /usr/include/c++/3.3/map:66,
from ../elements/local/smartqueue.hh:4,
from ../elements/local/smartqueue.cc:2:
/usr/include/string.h:38: error: parse error before `?' token
/usr/include/string.h:58: error: parse error before `?' token
In file included from /usr/include/c++/3.3/bits/stl_algobase.h:65,
from /usr/include/c++/3.3/bits/stl_tree.h:86,
from /usr/include/c++/3.3/map:66,
from ../elements/local/smartqueue.hh:4,
from ../elements/local/smartqueue.cc:2:
/usr/include/c++/3.3/cstring:79: error: `memcpy' not declared
/usr/include/c++/3.3/cstring:85: error: `memcmp' not declared
/usr/include/c++/3.3/cstring:93: error: `memset' not declared
In file included from /usr/include/limits.h:152,
from
/usr/lib/gcc-lib/i486-linux/3.3.5/include/limits.h:122,
from
/usr/lib/gcc-lib/i486-linux/3.3.5/include/syslimits.h:7,
from /usr/lib/gcc-lib/i486-linux/3.3.5/include/limits.h:11,
from /usr/include/c++/3.3/climits:49,
from /usr/include/c++/3.3/bits/stl_algobase.h:66,
from /usr/include/c++/3.3/bits/stl_tree.h:86,
from /usr/include/c++/3.3/map:66,
from ../elements/local/smartqueue.hh:4,
from ../elements/local/smartqueue.cc:2:
/usr/include/bits/xopen_lim.h:95:6: missing binary operator before token "("
/usr/include/bits/xopen_lim.h:98:7: missing binary operator before token "("
/usr/include/bits/xopen_lim.h:122:6: missing binary operator before
token "("
In file included from /usr/include/c++/3.3/cstdlib:52,
from /usr/include/c++/3.3/bits/stl_algobase.h:67,
from /usr/include/c++/3.3/bits/stl_tree.h:86,
from /usr/include/c++/3.3/map:66,
from ../elements/local/smartqueue.hh:4,
from ../elements/local/smartqueue.cc:2:
/usr/include/stdlib.h: In function `long unsigned int strtoul(const char*,
char**, int)':
/usr/include/stdlib.h:322: error: redefinition of `long unsigned int
strtoul(const char*, char**, int)'
../include/click/glue.hh:139: error: `long unsigned int strtoul(const char*,
char**, int)' previously defined here
In file included from /usr/include/stdlib.h:416,
from /usr/include/c++/3.3/cstdlib:52,
from /usr/include/c++/3.3/bits/stl_algobase.h:67,
from /usr/include/c++/3.3/bits/stl_tree.h:86,
from /usr/include/c++/3.3/map:66,
from ../elements/local/smartqueue.hh:4,
from ../elements/local/smartqueue.cc:2:
/usr/include/sys/types.h: At global scope:
/usr/include/sys/types.h:41: error: conflicting types for `typedef struct
__fsid_t fsid_t'
/usr/src/linux/include/asm/statfs.h:8: error: previous declaration as
`typedef
struct __kernel_fsid_t fsid_t'
/usr/include/sys/types.h:62: error: conflicting types for `typedef __dev_t
dev_t'
/usr/src/linux/include/linux/types.h:21: error: previous declaration as `
typedef __kernel_dev_t dev_t'
/usr/include/sys/types.h:72: error: conflicting types for `typedef __mode_t
mode_t'
/usr/src/linux/include/linux/types.h:23: error: previous declaration as `
typedef __kernel_mode_t mode_t'
/usr/include/sys/types.h:77: error: conflicting types for `typedef __nlink_t
nlink_t'
/usr/src/linux/include/linux/types.h:24: error: previous declaration as `
typedef __kernel_nlink_t nlink_t'
.
.
.
---------------------------------------------
small example that works:
#include <map>
#include <string>
#include <iostream>
using namespace std;
int main( )
{
map<string,double> salaries;
salaries["Pat"] = 75000.00;
cout << salaries["Pat"] << endl;
cout << salaries["Jan"] << endl;
map<string,double>::const_iterator itr;
itr = salaries.find("Chris");
if( itr == salaries.end( ) )
cout << "Not an employee of this company!" << endl;
else
cout << itr->second << endl;
return 0;
--------------------------------------------
output:
75000
0
Not an employee of this company!
Kind regards
Alan
More information about the click
mailing list