Code Search for Developers
 
 
  

attributeBase.h from GreenSocs at Krugle


Show attributeBase.h syntax highlighted

// LICENSETEXT
// 
//   Copyright (C) 2005,2006 :
//   GreenSocs Ltd
// 	(http://www.greensocs.com/),
// 
//   email: info@greensocs.com
// 
//     This program is free software; you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation; either version 2 of the License, or
//     (at your option) any later version.
// 
//     This program is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with this program; if not, write to the Free Software
//     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
// 
// ENDLICENSETEXT


#ifndef __ATTRIBUTEBASE_H__
#define __ATTRIBUTEBASE_H__

#include "utils/description.h"
#include "utils/class_wrapper.h"
#include <string>


namespace tlm {

  class AttributeRoot {
    public:
      AttributeRoot(){}
      virtual ~AttributeRoot(){}
    
      virtual std::string get_name()=0;
      virtual unsigned int get_length()=0;
      virtual unsigned char* serialize()=0;
      virtual void set_name(const char* _name)=0;
  };



// forward declaration necessary for stream operator declarations
template <class T, const char *d> class AttributeBase;

// stream operator declarations (implementation is in attributes.h)
template <class T, const char *d> std::istream& operator>> (std::istream &is, const AttributeBase<T,d> &obj);
template <class T, const char *d> std::ostream& operator<< (std::ostream &os, const AttributeBase<T,d> &obj);


//---------------------------------------------------------------------------
/**
 * Defines the basic attribute class.
 * You should to derive from this class to create you owner specific attributes.
 */
//---------------------------------------------------------------------------
template <class T, const char *d>
class AttributeBase : public T, public Description<d>, public AttributeRoot {
  
  friend std::ostream& operator<< <>(std::ostream&, AttributeBase<T,d>&);
  friend std::istream& operator>> <>(std::istream&, AttributeBase<T,d>&);    
  // see http://www.ica1.uni-stuttgart.de/Courses_and_Lectures/C++/script/node23.html
  
public:
  
  AttributeBase() {}
  AttributeBase(const T &v) : T(v) {}
  
  T& operator=(const T &obj) {T::operator=(obj);}
  
};


  
  //---------------------------------------------------------------------------
  /**
   * Specialization of AttributeBase for class_wrapper.
   */
  //---------------------------------------------------------------------------
  template <class T, const char *d>
  class AttributeBase<class_wrapper<T>,d> : public class_wrapper<T>, public Description<d>, public AttributeRoot {

  public:

    AttributeBase() : name("N/A") {}
    AttributeBase(const T &v) : class_wrapper<T>(v), name("N/A") {}
    void operator=(const AttributeBase<class_wrapper<T>,d> & obj) {this->class_wrapper<T>::value=obj.class_wrapper<T>::value; }
    AttributeBase(const AttributeBase<class_wrapper<T>,d> & obj){this->class_wrapper<T>::value=obj.class_wrapper<T>::value;}
    T& operator=(const T &obj) {return class_wrapper<T>::operator=(obj);}
    std::string get_name(){return name;} 
    unsigned int get_length() {return sizeof(T);} 
    unsigned char* serialize() { return (unsigned char*) &( this->class_wrapper<T>::value); }
    void set_name(const char* _name){ name=std::string(_name);}    
      
    
  private:
    std::string name;

  };

  
} // end of namespace tlm

#endif




See more files for this project here

GreenSocs

To develop SystemC infrustructure, basic IP, patches and add on library code for eventual standerdization.\r\nThe GreenSocs project is made up of a number of contributions (sub projects). Please visit www.greensocs.com for more information.

Project homepage: http://sourceforge.net/projects/greensocs
Programming language(s): C,C++,Java,Perl,XML
License: other

  attributeBase.h
  attributes.h
  tlm.h
  tlm_b_if.h
  tlm_port.h
  tlm_slave_if.h
  transactionBase.h