Savarese Software Research CorporationSava C++ Binding for Spread 1.0.2 Unit Test Coverage
Current view: directory - sava/spread - Message.h
Test: Sava C++/Lua/Perl/Python/Ruby Bindings for Spread 1.0.2 C++ Unit Tests
Date: 2008-04-13 Instrumented lines: 13
Code covered: 100.0 % Executed lines: 13

       1                 : /*
       2                 :  * $Id: Message.h 1125 2007-11-24 06:42:46Z dfs $
       3                 :  *
       4                 :  * Copyright 2006 Savarese Software Research Corporation
       5                 :  *
       6                 :  * Licensed under the Apache License, Version 2.0 (the "License");
       7                 :  * you may not use this file except in compliance with the License.
       8                 :  * You may obtain a copy of the License at
       9                 :  *
      10                 :  *     http://www.savarese.com/software/ApacheLicense-2.0
      11                 :  *
      12                 :  * Unless required by applicable law or agreed to in writing, software
      13                 :  * distributed under the License is distributed on an "AS IS" BASIS,
      14                 :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      15                 :  * See the License for the specific language governing permissions and
      16                 :  * limitations under the License.
      17                 :  */
      18                 : 
      19                 : /**
      20                 :  * @file
      21                 :  * This header defines the Message class.
      22                 :  */
      23                 : 
      24                 : #ifndef __SAVA_SPREAD_MESSAGE_H
      25                 : #define __SAVA_SPREAD_MESSAGE_H
      26                 : 
      27                 : #include <sava/spread/detail/ByteBuffer.h>
      28                 : #include <sava/spread/MembershipInfo.h>
      29                 : 
      30                 : __BEGIN_NS_SAVA_SPREAD
      31                 : 
      32                 : /**
      33                 :  * Message is a reusable and resizable data buffer for sending and
      34                 :  * receiving messages.  We do not document its protected members
      35                 :  * because they are intended only for internal library use.  All of
      36                 :  * its useful public methods are inherited from BaseMessage and
      37                 :  * detail::ByteBuffer.
      38                 :  *
      39                 :  * Please note that you can directly access the message data via
      40                 :  * indexing with detail::Buffer::operator[] or obtaining a pointer
      41                 :  * to the data via:
      42                 :  * <pre>&message[0]</pre>
      43                 :  * You can do this because detail::Buffer is derived from std::vector and we
      44                 :  * guarantee this behavior is defined even though we do not consider
      45                 :  * detail::Buffer to be part of the public API.
      46                 :  * Therefore, you will find you do not have to use detail::ByteBuffer::read
      47                 :  * unless you really have to make a copy of the data instead of using
      48                 :  * it directly.  However, you should use detail::ByteBuffer::write to avoid
      49                 :  * overrunning the buffer.
      50                 :  */
      51              19 : class Message : public BaseMessage, public detail::ByteBuffer {
      52                 : protected:
      53                 : 
      54                 : #ifdef LIBSAVASPREAD_ENABLE_MEMBERSHIP_INFO
      55                 : 
      56               3 :   virtual int sp_get_membership_info(Spread::membership_info *info) const {
      57               3 :     return Spread::SP_get_memb_info(&((*this)[0]), service(), info);
      58                 :   }
      59                 : 
      60                 :   virtual int sp_get_vs_set_members(const Spread::vs_set_info *vs_set,
      61                 :                                     Spread::group_type member_names[],
      62                 :                                     unsigned int member_names_count)
      63               3 :     const
      64                 :   {
      65                 :     return
      66                 :       Spread::SP_get_vs_set_members(&((*this)[0]), vs_set, member_names,
      67               3 :                                     member_names_count);
      68                 :   }
      69                 : 
      70                 :   virtual int sp_get_vs_sets_info(Spread::vs_set_info *vs_sets,
      71                 :                                   unsigned int num_vs_sets,
      72                 :                                   unsigned int *index)
      73               2 :     const
      74                 :   {
      75                 :     return
      76               2 :       Spread::SP_get_vs_sets_info(&((*this)[0]), vs_sets, num_vs_sets, index);
      77                 :   }
      78                 : 
      79                 : #endif
      80                 : 
      81                 : public:
      82                 : 
      83                 :   enum {
      84                 :     /** The default capacity used to construct a Message. */
      85                 :     DefaultCapacity = 4096
      86                 :   };
      87                 : 
      88                 :   /**
      89                 :    * Creates a Message with the specified initial capacity (or
      90                 :    * DefaultCapacity if no parameter is provided).  See BaseMessage()
      91                 :    * for the default values of various properties, including service
      92                 :    * type.
      93                 :    *
      94                 :    * @param capacity The initial capacity of the message.
      95                 :    */
      96              19 :   explicit Message(const unsigned int capacity = DefaultCapacity) :
      97              19 :     detail::ByteBuffer(capacity) { }
      98                 : 
      99              64 :   virtual unsigned int size() const throw() {
     100              64 :     return detail::ByteBuffer::size();
     101                 :   }
     102                 : 
     103               4 :   virtual void clear() {
     104               4 :     return detail::ByteBuffer::clear();
     105                 :   }
     106                 : 
     107                 : };
     108                 : 
     109                 : __END_NS_SAVA_SPREAD
     110                 : 
     111                 : #endif

Savarese Software Research Corporation