0

I created two special types that I want to use in my get_property_function.hpp in my application:

typedef boost::function<std::string ()> GetFunction;
typedef map<std::string, GetFunction> PropertyToGetFunction;

typedef boost::function<std::string (LPARAM)> GetEventFunction;
typedef map<std::string, GetEventFunction> PropertyToGetEventFunction;

I define the following lines in my PropertyManager.hpp:

PropertyToGetFunction create_get_map();
PropertyToGetEventFunction create_event_get_map();

PropertyToGetFunction property2getFunction;
PropertyToGetEventFunction property2getEventFunction;

I implement them in my PropertyManager.cpp:

PropertyToGetFunction PropertyManager::create_get_map()
{
    PropertyToGetFunction property2getFunction;


    property2getFunction[string("1.1.3.4.1.1")]=&getReceiptPrinter_DeviceCapability;

        ...

    return property2getFunction;
}

PropertyToGetEventFunction PropertyManager::create_event_get_map()
{
    PropertyToGetEventFunction property2getEventFunction;

    property2getEventFunction[string("105")]=&getPTRRetractBinThreshold_UserEvent;

        ...

    return property2getEventFunction;
}

The methods I assigned to my map are defined in get_property_function.

get_property_function.hpp:

...
std::string getPTRRetractBinThreshold_UserEvent(LPARAM lParam);
...

get_property_function.cpp:

...
std::string getPTRRetractBinThreshold_UserEvent(LPARAM lParam)
{
    string result = "";

    //I will do some process in here and will save it in result var.

    return result;
}
...

I use getPropertyValue to find the correct method in my map:

string PropertyManager::getPropertyValue(string property_id)
{   
    string result_value = "No Property Found";

    if (!isReadable(property_id))
    {
        return "Error";
    }
    else
    {
        PropertyToGetFunction::const_iterator it =property2getFunction.find(property_id);

        if ( it != property2getFunction.end() )
        {       
            GetFunction function = it->second;
            result_value = function();
        }
    }

    return result_value;
}

string PropertyManager::getPropertyValue(string property_id, LPARAM lParam)
{   
    string result_value = "No Property Found";

    if (!isReadable(property_id))
    {
        return "Error";
    }
    else
    {
        PropertyToGetEventFunction::const_iterator it = property2getEventFunction.find(property_id);

        if ( it != property2getEventFunction.end() )
        {       
            GetEventFunction function = it->second;
            result_value = function(lParam);
        }
    }

    return result_value;
}

getPropertyValue(string property_id) is working fine and I have no problems with that, but the getPropertyValue(string property_id, LPARAM lParam) causes a compile error:

1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(1144): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(1146): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char &)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(1148): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char *)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(1150): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char &)' [found using argument-dependent lookup]
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(155): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits> &(__cdecl *)(std::basic_istream<_Elem,_Traits> &))'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(161): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(168): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(175): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::_Bool &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(194): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(short &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(228): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned short &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(247): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(int &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(273): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned int &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(291): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(309): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__w64 unsigned long &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(329): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__int64 &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(348): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned __int64 &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(367): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(float &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(386): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(double &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(404): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long double &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(422): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(void *&)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        C:\Program Files\Microsoft Visual Studio 9.0\VC\include\istream(441): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_streambuf<_Elem,_Traits> *)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        while trying to match the argument list '(std::basic_istream<_Elem,_Traits>, LPWORD )'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        D:\programming\agent\compiled4vs2008\boost_v1.50.0\include\boost-1_50\boost/property_tree/stream_translator.hpp(35) : while compiling class template member function 'void boost::property_tree::customize_stream<Ch,Traits,E>::extract(std::basic_istream<_Elem,_Traits> &,E &)'
1>        with
1>        [
1>            Ch=char,
1>            Traits=std::char_traits<char>,
1>            E=LPWORD ,
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        D:\programming\agent\compiled4vs2008\boost_v1.50.0\include\boost-1_50\boost/property_tree/stream_translator.hpp(190) : see reference to class template instantiation 'boost::property_tree::customize_stream<Ch,Traits,E>' being compiled
1>        with
1>        [
1>            Ch=char,
1>            Traits=std::char_traits<char>,
1>            E=LPWORD 
1>        ]
1>        D:\programming\agent\compiled4vs2008\boost_v1.50.0\include\boost-1_50\boost/property_tree/stream_translator.hpp(186) : while compiling class template member function 'boost::optional<T> boost::property_tree::stream_translator<Ch,Traits,Alloc,E>::get_value(const std::basic_string<_Elem,_Traits,_Ax> &)'
1>        with
1>        [
1>            T=LPWORD ,
1>            Ch=char,
1>            Traits=std::char_traits<char>,
1>            Alloc=std::allocator<char>,
1>            E=LPWORD ,
1>            _Elem=char,
1>            _Traits=std::char_traits<char>,
1>            _Ax=std::allocator<char>
1>        ]
1>        D:\programming\agent\compiled4vs2008\boost_v1.50.0\include\boost-1_50\boost/property_tree/detail/ptree_implementation.hpp(661) : see reference to class template instantiation 'boost::property_tree::stream_translator<Ch,Traits,Alloc,E>' being compiled
1>        with
1>        [
1>            Ch=char,
1>            Traits=std::char_traits<char>,
1>            Alloc=std::allocator<char>,
1>            E=LPWORD 
1>        ]
1>        D:\programming\agent\compiled4vs2008\boost_v1.50.0\include\boost-1_50\boost/property_tree/detail/ptree_implementation.hpp(732) : see reference to function template instantiation 'Type boost::property_tree::basic_ptree<Key,Data>::get_value<Type>(void) const' being compiled
1>        with
1>        [
1>            Type=LPWORD,
1>            Key=std::string,
1>            Data=std::string
1>        ]
1>        ..\..\..\..\..\..\..\Source-Code\Device-Manager\source\property\get_property_functions.cpp(3328) : see reference to function template instantiation 'Type boost::property_tree::basic_ptree<Key,Data>::get<LPWORD>(const boost::property_tree::string_path<String,Translator> &) const' being compiled
1>        with
1>        [
1>            Type=LPWORD,
1>            Key=std::string,
1>            Data=std::string,
1>            String=std::string,
1>            Translator=boost::property_tree::id_translator<std::string>
1>        ]

I'm sure there is something wrong with my parameter definition in boost::function. Can you tell me what I do wrong?

Jamal
  • 763
  • 7
  • 22
  • 32
M.H.
  • 223
  • 3
  • 10
  • 23
  • What is "property_manager.cpp(189)"? What's the code on this line? – Igor R. Oct 02 '13 at 10:27
  • property2getFunction[string("105")] = &getPTRRetractBinThreshold_UserEvent; – M.H. Oct 02 '13 at 10:36
  • And what's the signature of `getPTRRetractBinThreshold_UserEvent`? – Igor R. Oct 02 '13 at 10:38
  • I updated my question and you can see it there man. – M.H. Oct 02 '13 at 10:48
  • I fixed the problem you mentioned as answer but still i have a problem, I updated my Question can you check again Igor ?! – M.H. Oct 02 '13 at 11:16
  • If you don't post sscce (see http://sscce.org/), could you please provide at least sufficient information about the errors you get? What's `get_property_functions.cpp(3328)`? – Igor R. Oct 02 '13 at 11:21
  • This is line causing the problem, I'm trying to fetch what i set before. Line 3328 is : LPWORD y = info.get(PathTree(Event)(lpwMThreshold).str()); and i set my info like this :: info.put(PathTree(Event)(lpwMThreshold).str(), m_threshold); – M.H. Oct 02 '13 at 11:29
  • Ok, but it's absolutely unrelated either to your initial question or to `boost::function`. We can't debug all your program in one SO question. Please, open another question, and provide *all* the relevant code there (preferably in *sscce* form). – Igor R. Oct 02 '13 at 11:37

1 Answers1

2

In the following line:

property2getFunction[string("105")] = &getPTRRetractBinThreshold_UserEvent

There's an attempt to assign a function having string(LPARAM) signature to a boost::function having string(void) signature (see your GetFunction type). That's why you get this compilation error.

You probably meant to use property2getEventFunction instead.

Igor R.
  • 14,716
  • 2
  • 49
  • 83