TLM-2.0: include/tlm/tlm_h/tlm_generic_payload/tlm_phase.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# include/tlm/tlm_h/tlm_generic_payload/tlm_phase.h

Go to the documentation of this file.

    00001 /*****************************************************************************
    00002
    00003   The following code is derived, directly or indirectly, from the SystemC
    00004   source code Copyright (c) 1996-2008 by all Contributors.
    00005   All Rights reserved.
    00006
    00007   The contents of this file are subject to the restrictions and limitations
    00008   set forth in the SystemC Open Source License Version 3.0 (the "License");
    00009   You may not use this file except in compliance with such restrictions and
    00010   limitations. You may obtain instructions on how to receive a copy of the
    00011   License at http://www.systemc.org/. Software distributed by Contributors
    00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
    00013   ANY KIND, either express or implied. See the License for the specific
    00014   language governing rights and limitations under the License.
    00015
    00016  *****************************************************************************/
    00017
    00018 #ifndef __TLM_PHASE_H__
    00019 #define __TLM_PHASE_H__
    00020
    00021 #include <string>
    00022 #include <iostream>
    00023 #include <vector>
    00024
    00025 namespace tlm {
    00026
    00027 //enum tlm_phase { BEGIN_REQ, END_REQ, BEGIN_RESP, END_RESP };
    00028
    00029 enum tlm_phase_enum { UNINITIALIZED_PHASE=0, BEGIN_REQ=1, END_REQ, BEGIN_RESP, END_RESP };
    00030
    00031 inline unsigned int create_phase_number(){
    00032   static unsigned int number=END_RESP+1;
    00033   return number++;
    00034 }
    00035
    00036 inline std::vector<const char*>& get_phase_name_vec(){
    00037   static std::vector<const char*> phase_name_vec(END_RESP+1, (const char*)NULL);
    00038   return phase_name_vec;
    00039 }
    00040
    00041 class tlm_phase{
    00042 public:
    00043   tlm_phase(): m_id(0) {}
    00044   tlm_phase(unsigned int id): m_id(id){}
    00045   tlm_phase(const tlm_phase_enum& standard): m_id((unsigned int) standard){}
    00046   tlm_phase& operator=(const tlm_phase_enum& standard){m_id=(unsigned int)standard; return *this;}
    00047   operator unsigned int() const{return m_id;}
    00048
    00049 private:
    00050   unsigned int m_id;
    00051 };
    00052
    00053 inline
    00054 std::ostream& operator<<(std::ostream& s, const tlm_phase& p){
    00055   switch ((unsigned int)p){
    00056     case UNINITIALIZED_PHASE: s<<"UNINITIALIZED_PHASE"; break;
    00057     case BEGIN_REQ:  s<<"BEGIN_REQ"; break;
    00058     case END_REQ:    s<<"END_REQ"; break;
    00059     case BEGIN_RESP: s<<"BEGIN_RESP"; break;
    00060     case END_RESP:   s<<"END_RESP"; break;
    00061     default:
    00062       s<<get_phase_name_vec()[(unsigned int)p]; return s;
    00063   }
    00064   return s;
    00065 }
    00066
    00067 #define DECLARE_EXTENDED_PHASE(name_arg) \
    00068 class tlm_phase_##name_arg:public tlm::tlm_phase{ \
    00069 public:\
    00070 static const tlm_phase_##name_arg& get_phase(){static tlm_phase_##name_arg tmp; return tmp;}\
    00071 private:\
    00072 tlm_phase_##name_arg():tlm::tlm_phase(tlm::create_phase_number()){tlm::get_phase_name_vec().push_back(get_char_##name_arg());};\
    00073 tlm_phase_##name_arg(const tlm_phase_##name_arg&); \
    00074 tlm_phase_##name_arg& operator=(const tlm_phase_##name_arg&); \
    00075 static inline const char* get_char_##name_arg(){static const char* tmp=#name_arg; return tmp;} \
    00076 }; \
    00077 static const tlm_phase_##name_arg& name_arg=tlm_phase_##name_arg::get_phase()
    00078
    00079 } // namespace tlm
    00080
    00081 #endif /* TLM_PHASE_HEADER */