Sign in to follow this  

Getting insuffcient contextual information to determine type - SOLVED

This topic is 4379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all I am currently implementing an event handling system and am having a little trouble spotting the cause of my compilation errors (using code::blocks RC1) Errors: src\EventSnooper.cpp:23: error: insufficient contextual information to determine type src\EventSnooper.cpp:24: error: insufficient contextual information to determine type EventSnooper.cpp:
namespace event
{
    // This will hold whatever we need
    CEventSnooper::CEventSnooper()
    {
    }
    
    CEventSnooper::~CEventSnooper()
    {
    }

    bool CEventSnooper::HandleEvent(CEvent const& event)
    {
        // Write event details to log file
        logger::CLogger::Instance()->Write(LOG_APP,
                                           "Event Snoop : event %081x time %g : type %ld [%s]",
                                           &event,
                                           event.GetTime(),
                                           event.GetType.GetIdent(), /* HERE - line 23 */
                                           event.GetType.GetStr().c_str() /* HERE - line 24*/
                                           );
    
        return false;
    }

}



Event.h:
#include "EventData.h"
#include "EventType.h"

namespace event
{
    class CEvent
    {
    	CEvent();
    	
        public:
        
            explicit CEvent(const char* pEventTypeName, 
                            double fTime = 0.f, 
                            IEventDataPtr pData = IEventDataPtr((IEventData*)NULL)) 
                            : type_(pEventTypeName),time_(fTime),userData_(pData)
            {}
                              
            explicit CEvent(const std::string& sEventType, 
                            double fTime = 0.f, 
                            IEventDataPtr pData = IEventDataPtr((IEventData*)NULL))
                            : type_(sEventType),
                              time_(fTime),
                              userData_(pData)
            {}
                              
            CEvent(const CEvent& e) : type_(e.type_), time_(e.time_), userData_(e.userData_)
            {}
            
            virtual ~CEvent()
            {}
            
            CEvent& operator=(const CEvent& rhs)
            {
                if (this != &rhs)
                {
                    type_ = rhs.type_;
                    time_ = rhs.time_;
                    userData_ = rhs.userData_;
                }
                
                return *this;
            }
                     
            const CEventType& GetType() const
            {
            	return type_;
            }
            
            double GetTime() const
            {
            	return time_;
            }
            
            IEventDataPtr GetData() const
            {
                return userData_;
            }
            
            template <typename T>
            T* GetDataPtr() const
            {
                return reinterpret_cast<T *>(userData_.get());
            }
            
            private:
            
                CEventType type_;           // Identified type of event
                double time_;                // Time the event fired
                IEventDataPtr userData_;    // Runtime provided data link,
                                            // may be NULL if no data associated.
    };
    
}



EventType.h:
namespace event
{
    const std::string sWildCardEventType = "*";
        
    class CEventType
    {
    	CEventType();
            
        public:
    
            static std::size_t hash_name(std::string identStr);
            
            explicit CEventType(const char* pIdentStr) : ident_(CEventType::hash_name(std::string(pIdentStr))), identStr_(pIdentStr)
            {}
            
            explicit CEventType(const std::string& identStr) : ident_(CEventType::hash_name(identStr)), identStr_(identStr)
            {}
            
            CEventType(const CEventType& et) : ident_(et.ident_), identStr_(et.identStr_)
            {}
            
            CEventType& operator=(const CEventType& rhs);
            
            std::size_t GetIdent() const
            {
            	return ident_;
            }
            
            const std::string& GetIdentStr() const
            {
            	return identStr_;
            }
            
            bool operator<(CEventType const& et) const
            {
                return (GetIdent() < et.GetIdent());
            }
            
            bool operator==(CEventType const& et) const;
            
            
        private:
            
            std::size_t ident_;
            std::string identStr_;
    };
		
			
}



Log.cpp:
namespace logger
{
	CLogger* CLogger::pLog = 0;

    CLogger::CLogger()
    {
    }
    
    CLogger::~CLogger()
    {
    }
    
    bool CLogger::Init()
    {
        // load localise strings
        if(!LoadStrings()) return false;
        
        m_bAlog = false;
        m_bClog = false;
        m_bSlog = false;
        
        return true;   
    }
    
    void CLogger::Free()
    {   
        std::cout << "CLogger freeing Log" << std::endl;
        std::cout << "CLogger freeing pLog" << std::endl;
	
        delete pLog;
	
        std::cout << "CLogger freed" << std::endl;
	
    }
    
    void CLogger::Write(int target, const char *msg, ...)
    {
	   va_list args; va_start(args,msg);
	   char szBuf[1024];
	   vsprintf(szBuf,msg,args);
	   
	   std::stringstream aStream; 
       
       aStream<<__TIME__<<":";
       aStream<<szBuf<<"\n";

	   if(target&LOG_APP)
	   {
            if (!m_bAlog)
            {
                appLog.open("applog.txt");
                m_bAlog = true;
            }

		  appLog << szBuf<<"\n";
#ifdef DEBUG
		  appLog.flush();
#endif
	   }
	   
	   if(target&LOG_CLIENT)
	   {
            if (!m_bClog)
            {
                clientLog.open("clientlog.txt");
                m_bClog = true;
            }
        
		  clientLog<< aStream.str();
#ifdef DEBUG
		  clientLog.flush();
#endif
	   }
	   
	   if(target&LOG_SERVER)
	   {
            if (!m_bSlog)
            {
                serverLog.open("serverlog.txt");
                m_bSlog = true;
            }
        
            serverLog<< aStream.str();
#ifdef DEBUG
            serverLog.flush();
#endif
	   }
	   
	   if(target&LOG_USER)
	   {
		  MessageBox(NULL,szBuf,"Message",MB_OK);
	   }
	   
	   va_end(args);
    }

    void CLogger::Write(int target, const unsigned long msgID, ...)
    {
	   va_list args; va_start(args, msgID);
	   char szBuf[1024];
	   vsprintf(szBuf,logStrings[msgID].c_str(),args);
	   Write(target,szBuf);
	   va_end(args);
    }
 
    bool CLogger::LoadStrings()
    {
	    std::ifstream inFile("data/messages.txt");
	    if(!inFile.is_open())return false;
	    
        std::string line;
        
		std::string::size_type strSize = 0;
		char strStart = 0;
		char strEnd = 0;

        while(!inFile.eof() && getline(inFile,line))
		{			
            /* Check for comments */
            if(line[0] == '#')
                continue;
                
			strSize = line.size();
			std::string message;
            unsigned long msgID = 0;
			int field = 1;
			int j = 0;
			bool breakLoop = false;
		
			for (int i = 0; i < strSize;)
			{
			
    			while (line[j] != ',' && j < strSize)
    			{
         			++j;
				}
				
    			switch (field)
    			{
					case 1:
					{	
						/* Do nothing - 1st field is just the message identifier */
					}
					break;
					
					case 2:
					{						
						msgID = atol((line.substr(i,j)).c_str());
					}
					break;
					
					case 3:
					{							
						message = line.substr(i,j);
					}
					break;
					
					default:
						std::cerr << "Unknown field in message file" << std::endl;
						breakLoop = true;
					break;
				}
				
				if (breakLoop)
				{
					break;	
				}

				++j;
    			i=j;
    			
    			if (field == 3)
					field = 1;
				else
					++field;
			}	
			
			logStrings.insert(stringsPair(msgID,message));
		}
		
	   return true;
    }

}



I'm pretty sure it's something simple, maybe even down to the fact that I'm not too sure what the error actually means. I've followed the code back to the CEventType.GetIdent() and CEventType.GetStr() member functions and they seem okay..well to me anyhow..so am a bit stuck at the moment. Can anyone shed any light on this? Thanks for looking. PS. Happy Christmas. [Edited by - garyfletcher on December 20, 2005 1:57:28 AM]

Share this post


Link to post
Share on other sites
ummm...isn't gettype a function?

So what's up with

event.GetType.GetIdent(), /* HERE - line 23 */
event.GetType.GetStr().c_str() /* HERE - line 24*/


(No parentheses?)

Share this post


Link to post
Share on other sites
I don't suggest that you do (use managed).

My point was to demonstrate how to get much of the functionality of managed delegates with just normal C++.

Share this post


Link to post
Share on other sites
Right, you don't need a .NET framework.

See that's the point of the article. Proper delegates should've been easy in C++ if the standards had been explicit. But the rules were vague and each compiler decided to implement member function pointers differently... wildly differently it turns out.

But this library is a magical way of reuniting all the compilers and platforms. I would at least read the article... it should open eyes. I've used it in several projects (though only on x86) and it "just works". I haven't had a need to worry about any compiler non-conformity issues.

Share this post


Link to post
Share on other sites
Have just taken a quick scan and does look like a very good way of implementing the amazingly horrible use of member function pointers...have used my own implementation AND boost's function libraries.

Am just trying to think how it might help with my event handler. The basic implemetation was to have classes/sub-systems that require to know about certain events subcribe to those events with the event manager and "listen" for events via an implemented event listener...I suppose that the "delegates" would be very useful for callback functions.

Have you any other ideas?

Share this post


Link to post
Share on other sites

This topic is 4379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this