added a few basic c++ classes
This commit is contained in:
parent
c0fb7692d6
commit
fe0a2a6d63
99
qse/include/qse/Hashable.hpp
Normal file
99
qse/include/qse/Hashable.hpp
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _QSE_HASHABLE_HPP_
|
||||
#define _QSE_HASHABLE_HPP_
|
||||
|
||||
#include <qse/Types.hpp>
|
||||
|
||||
/////////////////////////////////
|
||||
QSE_BEGIN_NAMESPACE(QSE)
|
||||
/////////////////////////////////
|
||||
|
||||
class QSE_EXPORT Hashable
|
||||
{
|
||||
public:
|
||||
virtual ~Hashable () {}
|
||||
|
||||
virtual qse_size_t getHashCode () const = 0;
|
||||
|
||||
static qse_size_t getHashCode (qse_size_t init, const qse_char_t* str)
|
||||
{
|
||||
qse_size_t n = init;
|
||||
|
||||
while (*str != QSE_T('\0'))
|
||||
{
|
||||
const qse_uint8_t* p = (const qse_uint8_t*)str;
|
||||
for (qse_size_t i = 0; i < QSE_SIZEOF(*str); i++)
|
||||
n = n * 31 + *p++;
|
||||
str++;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static qse_size_t getHashCode (const qse_char_t* str)
|
||||
{
|
||||
return getHashCode (0, str);
|
||||
}
|
||||
|
||||
static qse_size_t getHashCode (qse_size_t init, const void* data, qse_size_t size)
|
||||
{
|
||||
qse_size_t n = init;
|
||||
const qse_uint8_t* p = (const qse_uint8_t*)data;
|
||||
|
||||
/*
|
||||
for (qse_size_t i = 0; i < size; i++) {
|
||||
n <<= 1;
|
||||
n += *p++;
|
||||
}
|
||||
*/
|
||||
|
||||
for (qse_size_t i = 0; i < size; i++) n = n * 31 + *p++;
|
||||
|
||||
/*
|
||||
for (qse_size_t i = 0; i < size; i++) {
|
||||
n = (n << 4) + *p++;
|
||||
//qse_size_t g = n & 0xF0000000U;
|
||||
qse_size_t g = n & ((qse_size_t)0xF << (qse_sizeof(qse_size_t) * 8 - 4));
|
||||
n &= ~g;
|
||||
}
|
||||
*/
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static qse_size_t getHashCode (const void* data, qse_size_t size)
|
||||
{
|
||||
return getHashCode (0, data, size);
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////
|
||||
QSE_END_NAMESPACE(QSE)
|
||||
/////////////////////////////////
|
||||
|
||||
#endif
|
@ -7,7 +7,7 @@ pkginclude_HEADERS = \
|
||||
types.h macros.h pack1.h unpack.h
|
||||
|
||||
if ENABLE_CXX
|
||||
pkginclude_HEADERS += Types.hpp
|
||||
pkginclude_HEADERS += Types.hpp Hashable.hpp Uncopyable.hpp RefCounted.hpp
|
||||
endif
|
||||
|
||||
install-data-hook:
|
||||
|
79
qse/include/qse/RefCounted.hpp
Normal file
79
qse/include/qse/RefCounted.hpp
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _QSE_REFCOUNTED_HPP_
|
||||
#define _QSE_REFCOUNTED_HPP_
|
||||
|
||||
#include <qse/Uncopyable.hpp>
|
||||
|
||||
/////////////////////////////////
|
||||
QSE_BEGIN_NAMESPACE(QSE)
|
||||
/////////////////////////////////
|
||||
|
||||
class QSE_EXPORT RefCounted: public Uncopyable
|
||||
{
|
||||
protected:
|
||||
RefCounted ()
|
||||
{
|
||||
this->ref_count = 0;
|
||||
}
|
||||
|
||||
public:
|
||||
virtual ~RefCounted ()
|
||||
{
|
||||
QSE_ASSERT (this->ref_count == 0);
|
||||
}
|
||||
|
||||
void ref () const
|
||||
{
|
||||
this->ref_count++;
|
||||
}
|
||||
|
||||
void deref (bool kill = true) const
|
||||
{
|
||||
if (--this->ref_count == 0 && kill) delete this;
|
||||
}
|
||||
|
||||
qse_size_t count () const
|
||||
{
|
||||
return this->ref_count;
|
||||
}
|
||||
|
||||
bool isShared () const
|
||||
{
|
||||
return this->ref_count > 1;
|
||||
}
|
||||
|
||||
protected:
|
||||
mutable qse_size_t ref_count;
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
QSE_END_NAMESPACE(QSE)
|
||||
/////////////////////////////////
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Sed.hpp 127 2009-05-07 13:15:04Z baconevi $
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
|
52
qse/include/qse/Uncopyable.hpp
Normal file
52
qse/include/qse/Uncopyable.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _QSE_UNCOPYABLE_HPP_
|
||||
#define _QSE_UNCOPYABLE_HPP_
|
||||
|
||||
#include <qse/Types.hpp>
|
||||
|
||||
/////////////////////////////////
|
||||
QSE_BEGIN_NAMESPACE(QSE)
|
||||
/////////////////////////////////
|
||||
|
||||
class QSE_EXPORT Uncopyable
|
||||
{
|
||||
public:
|
||||
Uncopyable () {}
|
||||
//virtual ~Uncopyable () {}
|
||||
|
||||
private:
|
||||
Uncopyable (const Uncopyable&);
|
||||
const Uncopyable& operator= (const Uncopyable&);
|
||||
};
|
||||
|
||||
/////////////////////////////////
|
||||
QSE_END_NAMESPACE(QSE)
|
||||
/////////////////////////////////
|
||||
|
||||
|
||||
#endif
|
@ -715,8 +715,16 @@ static int dns_recv (qse_httpd_t* httpd, qse_httpd_dns_t* dns, qse_httpd_hnd_t h
|
||||
if (*plptr > 63)
|
||||
{
|
||||
/* TODO TODO TODO TODO */
|
||||
/* this is not really right. each segment can be pointing to
|
||||
* somewhere else. TODO: fix the problem. dn_legnth() needs
|
||||
|
||||
/* RFC1035
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | 1 1| OFFSET |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
*/
|
||||
|
||||
/* this is not really right. the second segment or the
|
||||
* subsequent segments can be pointing to somewhere else.
|
||||
* TODO: fix the problem. dn_legnth() needs
|
||||
* to use the original request packet also */
|
||||
dnlen = 2;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user