mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-05-20 21:08:36 +02:00
Moved gcc atomic functions from source file to header file.
Moved ostream operator << from object.cpp to object.hpp Removed object.cpp Modernize configure.in
This commit is contained in:
parent
e0d1e5c722
commit
40ad7da455
@ -63,12 +63,6 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
" MSGPACK_ENABLE_GCC_CXX_ATOMIC)
|
||||
|
||||
IF (MSGPACK_ENABLE_CXX)
|
||||
LIST (APPEND msgpack_SOURCES
|
||||
src/object.cpp
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_ENABLE_GCC_CXX_ATOMIC)
|
||||
LIST (APPEND msgpack_SOURCES
|
||||
src/gcc_atomic.cpp
|
||||
|
@ -1,6 +1,6 @@
|
||||
AC_INIT(src/object.cpp)
|
||||
AC_INIT([msgpack], [0.5.9])
|
||||
AC_CONFIG_AUX_DIR(ac)
|
||||
AM_INIT_AUTOMAKE(msgpack, 0.5.9)
|
||||
AM_INIT_AUTOMAKE
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
|
||||
|
||||
@ -106,7 +106,6 @@ fi
|
||||
|
||||
AM_CONDITIONAL(ENABLE_GCC_CXX_ATOMIC, test "$enable_gcc_cxx_atomic" = "yes")
|
||||
|
||||
|
||||
major=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
|
||||
minor=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
|
||||
AC_SUBST(VERSION_MAJOR, $major)
|
||||
|
@ -8,14 +8,8 @@ libmsgpack_la_SOURCES = \
|
||||
vrefbuffer.c \
|
||||
zone.c
|
||||
|
||||
if ENABLE_CXX
|
||||
libmsgpack_la_SOURCES += \
|
||||
object.cpp
|
||||
endif
|
||||
|
||||
if ENABLE_GCC_CXX_ATOMIC
|
||||
libmsgpack_la_SOURCES += \
|
||||
gcc_atomic.cpp
|
||||
CXXFLAGS="$CXXFLAGS -DENABLE_GCC_CXX_ATOMIC"
|
||||
endif
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ atomic operations
|
||||
// MessagePack for C++ old gcc workaround for atomic operation
|
||||
//
|
||||
// Copyright (C) 2008-2013 FURUHASHI Sadayuki
|
||||
// Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@ -16,6 +16,10 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#ifndef MSGPACK_GCC_ATOMIC_HPP
|
||||
#define MSGPACK_GCC_ATOMIC_HPP
|
||||
|
||||
#ifdef ENABLE_GCC_CXX_ATOMIC
|
||||
#if defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)
|
||||
|
||||
#include "gcc_atomic.h"
|
||||
@ -31,5 +35,7 @@ int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr)
|
||||
return __gnu_cxx::__exchange_and_add(ptr, 1) + 1;
|
||||
}
|
||||
|
||||
|
||||
#endif // old gcc workaround
|
||||
#endif // ENABLE_GCC_CXX_ATOMIC
|
||||
|
||||
#endif /* gcc_atomic.hpp */
|
@ -412,6 +412,67 @@ packer<Stream>& operator<< (packer<Stream>& o, const object& v)
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream& operator<< (std::ostream& s, const object o)
|
||||
{
|
||||
switch(o.type) {
|
||||
case type::NIL:
|
||||
s << "nil";
|
||||
break;
|
||||
|
||||
case type::BOOLEAN:
|
||||
s << (o.via.boolean ? "true" : "false");
|
||||
break;
|
||||
|
||||
case type::POSITIVE_INTEGER:
|
||||
s << o.via.u64;
|
||||
break;
|
||||
|
||||
case type::NEGATIVE_INTEGER:
|
||||
s << o.via.i64;
|
||||
break;
|
||||
|
||||
case type::DOUBLE:
|
||||
s << o.via.dec;
|
||||
break;
|
||||
|
||||
case type::RAW:
|
||||
(s << '"').write(o.via.raw.ptr, o.via.raw.size) << '"';
|
||||
break;
|
||||
|
||||
case type::ARRAY:
|
||||
s << "[";
|
||||
if(o.via.array.size != 0) {
|
||||
object* p(o.via.array.ptr);
|
||||
s << *p;
|
||||
++p;
|
||||
for(object* const pend(o.via.array.ptr + o.via.array.size);
|
||||
p < pend; ++p) {
|
||||
s << ", " << *p;
|
||||
}
|
||||
}
|
||||
s << "]";
|
||||
break;
|
||||
|
||||
case type::MAP:
|
||||
s << "{";
|
||||
if(o.via.map.size != 0) {
|
||||
object_kv* p(o.via.map.ptr);
|
||||
s << p->key << "=>" << p->val;
|
||||
++p;
|
||||
for(object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
p < pend; ++p) {
|
||||
s << ", " << p->key << "=>" << p->val;
|
||||
}
|
||||
}
|
||||
s << "}";
|
||||
break;
|
||||
|
||||
default:
|
||||
// FIXME
|
||||
s << "#<UNKNOWN " << (uint16_t)o.type << ">";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@ -42,7 +42,13 @@ typedef long _msgpack_atomic_counter_t;
|
||||
#define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr)
|
||||
#define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr)
|
||||
#elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#define _msgpack_atomic_counter_header "gcc_atomic.hpp"
|
||||
#else
|
||||
#define _msgpack_atomic_counter_header "gcc_atomic.h"
|
||||
#endif
|
||||
|
||||
#else
|
||||
typedef unsigned int _msgpack_atomic_counter_t;
|
||||
#define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1)
|
||||
|
@ -1,87 +0,0 @@
|
||||
//
|
||||
// MessagePack for C++ dynamic typed objects
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "msgpack/object.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
|
||||
std::ostream& operator<< (std::ostream& s, const object o)
|
||||
{
|
||||
switch(o.type) {
|
||||
case type::NIL:
|
||||
s << "nil";
|
||||
break;
|
||||
|
||||
case type::BOOLEAN:
|
||||
s << (o.via.boolean ? "true" : "false");
|
||||
break;
|
||||
|
||||
case type::POSITIVE_INTEGER:
|
||||
s << o.via.u64;
|
||||
break;
|
||||
|
||||
case type::NEGATIVE_INTEGER:
|
||||
s << o.via.i64;
|
||||
break;
|
||||
|
||||
case type::DOUBLE:
|
||||
s << o.via.dec;
|
||||
break;
|
||||
|
||||
case type::RAW:
|
||||
(s << '"').write(o.via.raw.ptr, o.via.raw.size) << '"';
|
||||
break;
|
||||
|
||||
case type::ARRAY:
|
||||
s << "[";
|
||||
if(o.via.array.size != 0) {
|
||||
object* p(o.via.array.ptr);
|
||||
s << *p;
|
||||
++p;
|
||||
for(object* const pend(o.via.array.ptr + o.via.array.size);
|
||||
p < pend; ++p) {
|
||||
s << ", " << *p;
|
||||
}
|
||||
}
|
||||
s << "]";
|
||||
break;
|
||||
|
||||
case type::MAP:
|
||||
s << "{";
|
||||
if(o.via.map.size != 0) {
|
||||
object_kv* p(o.via.map.ptr);
|
||||
s << p->key << "=>" << p->val;
|
||||
++p;
|
||||
for(object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
p < pend; ++p) {
|
||||
s << ", " << p->key << "=>" << p->val;
|
||||
}
|
||||
}
|
||||
s << "}";
|
||||
break;
|
||||
|
||||
default:
|
||||
// FIXME
|
||||
s << "#<UNKNOWN " << (uint16_t)o.type << ">";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
} // namespace msgpack
|
||||
|
Loading…
x
Reference in New Issue
Block a user