Changeset 20167 for lang/c

Show
Ignore:
Timestamp:
09/28/08 22:05:11 (5 years ago)
Author:
frsyuki
Message:

lang/c/msgpack: C++ binding: pack()

Location:
lang/c/msgpack/trunk/cpp
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • lang/c/msgpack/trunk/cpp/object.hpp

    r20114 r20167  
    8484         
    8585 
    86 namespace type { 
    87         template <typename T> 
    88         inline T& operator>> (object o, T& v) 
    89         { 
    90                 v.msgpack_unpack(o); 
    91                 return v; 
    92         } 
    93          
    94         template <typename Stream, typename T> 
    95         inline packer<Stream>& operator<< (packer<Stream>& o, const T& v) 
    96         { 
    97                 pack_copy(v.msgpack_pack(), o); 
    98                 return o; 
    99         } 
     86template <typename T> 
     87inline T& operator>> (object o, T& v) 
     88{ 
     89        v.msgpack_unpack(o); 
     90        return v; 
     91} 
     92 
     93template <typename Stream, typename T> 
     94inline packer<Stream>& operator<< (packer<Stream>& o, const T& v) 
     95{ 
     96        o << v.msgpack_pack(); 
     97        return o; 
    10098} 
    10199 
     
    104102inline void convert(T& v, object o) 
    105103{ 
    106         using namespace type; 
    107104        o >> v; 
    108105} 
    109106 
    110  
    111 template <typename Stream, typename T> 
    112 inline void pack(T& v, packer<Stream>& o) 
    113 { 
    114         using namespace type; 
     107template <typename Stream, typename T> 
     108inline void pack(packer<Stream>& o, const T& v) 
     109{ 
    115110        o << v; 
    116111} 
    117112 
    118  
    119 template <typename Stream, typename T> 
    120 inline void pack(T& v, Stream& s) 
     113template <typename Stream, typename T> 
     114inline void pack(Stream& s, const T& v) 
    121115{ 
    122116        packer<Stream> pk(s); 
    123         pack(v, pk); 
    124 } 
    125  
    126  
    127 template <typename Stream, typename T> 
    128 inline void pack_copy(T v, packer<Stream>& o) 
    129 { 
    130         pack(v, o); 
     117        pack(pk, v); 
     118} 
     119 
     120template <typename Stream, typename T> 
     121inline void pack_copy(packer<Stream>& o, T v) 
     122{ 
     123        pack(o, v); 
    131124} 
    132125 
  • lang/c/msgpack/trunk/cpp/test.cpp

    r19275 r20167  
    2727                        try { 
    2828                                std::stringstream s; 
    29                                 pack(should, s); 
     29                                pack(s, should); 
    3030                                std::string str(s.str()); 
    3131                                object ro = unpack(str.data(), str.size(), m_zone); 
     
    140140        { 
    141141                for(unsigned i=0; i < TASK_REPEAT; ++i) { 
    142                         pack(task, stream); 
     142                        pack(stream, task); 
    143143                } 
    144144                std::cout << "send " << stream.str().size() << " bytes" << std::endl; 
  • lang/c/msgpack/trunk/cpp/type/array.hpp

    r20114 r20167  
    4646        for(typename std::vector<T>::const_iterator it(v.begin()), it_end(v.end()); 
    4747                        it != it_end; ++it) { 
    48                 pack(*it, o); 
     48                pack(o, *it); 
    4949        } 
    5050        return o; 
  • lang/c/msgpack/trunk/cpp/type/boolean.hpp

    r20114 r20167  
    2323 
    2424namespace msgpack { 
    25 namespace type { 
    2625 
    2726 
    2827inline bool& operator>> (object o, bool& v) 
    2928{ 
    30         if(o.type != BOOLEAN) { throw type_error(); } 
     29        if(o.type != type::BOOLEAN) { throw type_error(); } 
    3130        v = o.via.boolean; 
    3231        return v; 
     
    4342 
    4443 
    45 }  // namespace type 
    4644}  // namespace msgpack 
    4745 
  • lang/c/msgpack/trunk/cpp/type/integer.hpp

    r20114 r20167  
    7171        template <typename T, typename Stream> 
    7272        struct pack_integer_size_sign<T, Stream, 1, true> { 
    73                 static inline void pack(T v, packer<Stream>& o) 
     73                static inline void pack(packer<Stream>& o, T v) 
    7474                        { o.pack_int8(v); } 
    7575        }; 
     
    7777        template <typename T, typename Stream> 
    7878        struct pack_integer_size_sign<T, Stream, 1, false> { 
    79                 static inline void pack(T v, packer<Stream>& o) 
     79                static inline void pack(packer<Stream>& o, T v) 
    8080                        { o.pack_uint8(v); } 
    8181        }; 
     
    8383        template <typename T, typename Stream> 
    8484        struct pack_integer_size_sign<T, Stream, 2, true> { 
    85                 static inline void pack(T v, packer<Stream>& o) { 
     85                static inline void pack(packer<Stream>& o, T v) { 
    8686                        if( (int16_t)v <= (int16_t)std::numeric_limits<int8_t>::max() && 
    8787                                (int16_t)v >= (int16_t)std::numeric_limits<int8_t>::min()) 
     
    9393        template <typename T, typename Stream> 
    9494        struct pack_integer_size_sign<T, Stream, 2, false> { 
    95                 static inline void pack(T v, packer<Stream>& o) { 
     95                static inline void pack(packer<Stream>& o, T v) { 
    9696                        if( (uint16_t)v <= (uint16_t)std::numeric_limits<uint8_t>::max()) 
    9797                                { o.pack_uint8(v); } 
     
    102102        template <typename T, typename Stream> 
    103103        struct pack_integer_size_sign<T, Stream, 4, true> { 
    104                 static inline void pack(T v, packer<Stream>& o) { 
     104                static inline void pack(packer<Stream>& o, T v) { 
    105105                        if( (int32_t)v <= (int32_t)std::numeric_limits<int8_t>::max() && 
    106106                                (int32_t)v >= (int32_t)std::numeric_limits<int8_t>::min()) 
     
    115115        template <typename T, typename Stream> 
    116116        struct pack_integer_size_sign<T, Stream, 4, false> { 
    117                 static inline void pack(T v, packer<Stream>& o) { 
     117                static inline void pack(packer<Stream>& o, T v) { 
    118118                        if( (uint32_t)v <= (uint32_t)std::numeric_limits<uint8_t>::max()) 
    119119                                { o.pack_uint8(v); } 
     
    126126        template <typename T, typename Stream> 
    127127        struct pack_integer_size_sign<T, Stream, 8, true> { 
    128                 static inline void pack(T v, packer<Stream>& o) { 
     128                static inline void pack(packer<Stream>& o, T v) { 
    129129                        if( (int64_t)v <= (int64_t)std::numeric_limits<int8_t>::max() && 
    130130                                (int64_t)v >= (int64_t)std::numeric_limits<int8_t>::min()) 
     
    142142        template <typename T, typename Stream> 
    143143        struct pack_integer_size_sign<T, Stream, 8, false> { 
    144                 static inline void pack(T v, packer<Stream>& o) { 
     144                static inline void pack(packer<Stream>& o, T v) { 
    145145                        if( (uint64_t)v <= (uint64_t)std::numeric_limits<uint8_t>::max()) 
    146146                                { o.pack_uint8(v); } 
     
    157157        static inline void pack_integer(T v, packer<Stream>& o) 
    158158        { 
    159                 pack_integer_size_sign<T, Stream, sizeof(T), std::numeric_limits<T>::is_signed>::pack(v, o); 
     159                pack_integer_size_sign<T, Stream, sizeof(T), std::numeric_limits<T>::is_signed>::pack(o, v); 
    160160        } 
    161161 
  • lang/c/msgpack/trunk/cpp/type/map.hpp

    r20114 r20167  
    6464        for(typename type::assoc_vector<K,V>::const_iterator it(v.begin()), it_end(v.end()); 
    6565                        it != it_end; ++it) { 
    66                 pack(it->first, o); 
    67                 pack(it->second, o); 
     66                pack(o, it->first); 
     67                pack(o, it->second); 
    6868        } 
    6969        return o; 
     
    9898        for(typename std::map<K,V>::const_iterator it(v.begin()), it_end(v.end()); 
    9999                        it != it_end; ++it) { 
    100                 pack(it->first, o); 
    101                 pack(it->second, o); 
     100                pack(o, it->first); 
     101                pack(o, it->second); 
    102102        } 
    103103        return o; 
     
    126126        for(typename std::multimap<K,V>::const_iterator it(v.begin()), it_end(v.end()); 
    127127                        it != it_end; ++it) { 
    128                 pack(it->first, o); 
    129                 pack(it->second, o); 
     128                pack(o, it->first); 
     129                pack(o, it->second); 
    130130        } 
    131131        return o; 
  • lang/c/msgpack/trunk/cpp/type/tuple.hpp.erb

    r20114 r20167  
    143143        o.pack_array(<%=i+1%>); 
    144144        <%0.upto(i) {|j|%> 
    145         pack(v.template get<<%=j%>>(), o);<%}%> 
     145        pack(o, v.template get<<%=j%>>());<%}%> 
    146146        return o; 
    147147} 
  • lang/c/msgpack/trunk/cpp/unpack.hpp

    r20114 r20167  
    8282        //     // 2. 
    8383        //     ssize_t bytes = 
    84         //         read(the_source, pac.buffer, pac.buffer_capacity()); 
     84        //         read(the_source, pac.buffer(), pac.buffer_capacity()); 
    8585        // 
    8686        //     // error handling ...