Changeset 11 in libcf++


Ignore:
Timestamp:
06/08/15 21:27:49 (9 years ago)
Author:
cheese
Message:

#1 add new interfaces for bin and task

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/cf/bin.h

    r7 r11  
    1111
    1212#include <vector>
     13#include <string>
    1314#include <stdio.h>
    1415
     
    3839         * @param in asciiz-byte
    3940         */
    40         bin(const cf::char_t * in);
     41        bin(const std::string & in);
    4142
    4243        /**
     
    116117
    117118        /**
    118          * set 
     119         * set
    119120         * @param in bin
    120121         */
    121122        bin & operator =(const bin & in);
     123
     124        /**
     125         * set
     126         * @param in string
     127         */
     128        bin & operator =(const std::string & in);
    122129
    123130        /**
     
    151158
    152159        /**
     160         * get a byte
     161         * @return a byte
     162         * @param index index
     163         */
     164        cf::uint8_t operator [](const cf::size_t index) const;
     165
     166        /**
     167         * get as string
     168         * @return string
     169         */
     170        std::string toString() const;
     171
     172        /**
    153173         * dump binary to file-pointer
    154174         * @param prefix prefix for output
  • trunk/include/cf/network.h

    r10 r11  
    245245             * host to network long
    246246             * @return long for network
    247              * @param long for host
     247             * @param in long for host
    248248             */
    249249            static cf::uint32_t htonl(cf::uint32_t in);
     
    252252             * host to network short
    253253             * @return short for network
    254              * @param short for host
     254             * @param in short for host
    255255             */
    256256            static cf::uint16_t htons(cf::uint16_t in);
     
    259259             * network to host long
    260260             * @return long for host
    261              * @param long for network
     261             * @param in long for network
    262262             */
    263263            static cf::uint32_t ntohl(cf::uint32_t in);
     
    266266             * network to host short
    267267             * @return short for host
    268              * @param short for network
     268             * @param in short for network
    269269             */
    270270            static cf::uint16_t ntohs(cf::uint16_t in);
  • trunk/include/cf/task.h

    r7 r11  
    99#include "cf/exception.h"
    1010
    11 #define SYNCHRONIZED(_s)    for (cf::task::scopedLock _sl(&_s) ; _sl.synchronizer()->locked() ; _sl.synchronizer()->unlock())
     11#define SYNCHRONIZED(_s)    for (cf::task::scopedLock _sl(&_s) ; _sl.locked() ; _sl.unlock())
    1212
    1313namespace cf
     
    116116
    117117            /**
    118              * get synchronizer
    119              * @return an instance of synchronizer
    120              */
    121             ISynchronizer * synchronizer();
     118             * is locked ?
     119             * @return true; false
     120             */
     121            cf::bool_t locked() const;
     122
     123            /**
     124             * unlock
     125             */
     126            cf::void_t unlock()
     127                throw (cf::exception);
    122128        };
    123129
  • trunk/src/bin.cpp

    r10 r11  
    1515}
    1616
    17 cf::bin::bin(const cf::char_t * in)
     17cf::bin::bin(const std::string & in)
     18    : mBin(in.begin(), in.end())
    1819{
    19     if (!in)
    20         return;
    21 
    22     set(reinterpret_cast<const cf::uint8_t *>(in),
    23         strlen(reinterpret_cast<const char *>(in)));
    2420}
    2521
     
    9894}
    9995
     96cf::bin & cf::bin::operator =(const std::string & in)
     97{
     98    mBin.assign(in.begin(), in.end());
     99    return *this;
     100}
     101
    100102cf::void_t cf::bin::operator +=(const cf::bin & in)
    101103{
     
    122124}
    123125
     126cf::uint8_t cf::bin::operator [](const cf::size_t index) const
     127{
     128    if (index > size())
     129        THROW_EXCEPTION("invalid index");
     130
     131    return mBin[index];
     132}
     133
    124134cf::size_t cf::bin::find(const cf::uint8_t * in,
    125135                         const cf::size_t length) const
     
    137147
    138148    return -1;
     149}
     150
     151std::string cf::bin::toString() const
     152{
     153    return std::string(mBin.begin(), mBin.end());
    139154}
    140155
  • trunk/src/task.cpp

    r4 r11  
    145145    : mSynchronizer(inst)
    146146{
    147     if (!synchronizer())
     147    if (!mSynchronizer)
    148148        THROW_EXCEPTION("invalid synchronizer");
    149149
    150     synchronizer()->lock();
     150    mSynchronizer->lock();
    151151}
    152152
     
    155155    try
    156156    {
    157         synchronizer()->unlock();
     157        unlock();
    158158    }
    159159    catch (...)
     
    162162}
    163163
    164 cf::task::ISynchronizer * cf::task::scopedLock::synchronizer()
    165 {
    166     return mSynchronizer;
     164cf::bool_t cf::task::scopedLock::locked() const
     165{
     166    return mSynchronizer->locked();
     167}
     168
     169cf::void_t cf::task::scopedLock::unlock()
     170    throw (cf::exception)
     171{
     172    mSynchronizer->unlock();
    167173}
    168174
Note: See TracChangeset for help on using the changeset viewer.