zoukankan      html  css  js  c++  java
  • c++缓冲区 vbuffer.hpp

    //vov
    
    #ifndef VBUFFER_HPP
    #define VBUFFER_HPP
    
    #include <iostream>
    #include <deque>
    
    template <class T>
    class vBuffer
    {
        std::deque<T> dbuf_;
        int len_;
        std::mutex mtx_;
    public:
        vBuffer();
        vBuffer(int len);
        ~vBuffer();
        void push_back(T data);
        void pop_front();
        T top();
        T back();
        int size();
        void clear();
    private:
        //拷贝构造函数
        vBuffer(const vBuffer& t) {}
        //赋值构造函数
        vBuffer& operator=(const vBuffer& t) {}
    };
    
    template <class T>
    vBuffer<T>::vBuffer() {
        len_=1024;
    }
    
    template <class T>
    vBuffer<T>::vBuffer(int len) {
        len_=(len>1024||len<1)?1024:len;
    }
    
    template <class T>
    vBuffer<T>::~vBuffer() {
    }
    
    template <class T>
    void vBuffer<T>::push_back(T data) {
        if(dbuf_.size()==(unsigned int)len_) {
            dbuf_.pop_front();
            std::cout<<"[vBuffer]buffer is full:loss one data"<<std::endl;
        }
        dbuf_.push_back(data);
    }
    
    template <class T>
    void vBuffer<T>::pop_front() {
        if(!dbuf_.empty())
            dbuf_.pop_front();
    }
    
    template <class T>
    T vBuffer<T>::top() {
        T data;
        if(!dbuf_.empty()) {
            data=dbuf_.front();
        }
    
        return data;
    }
    
    template <class T>
    T vBuffer<T>::back() {
        if(!dbuf_.empty())
            return dbuf_.back();
    }
    
    template <class T>
    int vBuffer<T>::size() {
        return dbuf_.size();
    }
    
    template <class T>
    void vBuffer<T>::clear() {
        if(!dbuf_.empty())
            dbuf_.clear();
    }
    #endif
    
  • 相关阅读:
    Spring AOP
    Spring Bean的生命周期
    MySQL中的SQL的常见优化策略
    垃圾收集器
    JWT
    Zookeeper
    RabbitMQ原理介绍
    kafka 安装配置
    kafka 简介
    ELK logstash 各种报错
  • 原文地址:https://www.cnblogs.com/smallredness/p/10758518.html
Copyright © 2011-2022 走看看