Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411430 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 20, 2024, 12:27:10 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Boost.Python and classes....
Pages: [1]
Print
Author Topic: Boost.Python and classes....  (Read 1451 times)
makerimages
Level 2
**


Makerimages Studios


View Profile WWW
« on: December 15, 2014, 10:20:02 AM »

Welp, I need help. Boost.Python... trying to make it so my python code could swap languages at will... The following code throws a error: expected primary-expression before ')' token in the PythonSUpport.cpp line 10.

PythonSupport.cpp
Code:
#include <cmath>
#include <boost/python.hpp>
#include "Language.h"

using namespace twile;
using namespace boost::python;

BOOST_PYTHON_MODULE(twile) {
    class_<Language>("Language").def("swapLanguage", &Language::swapLanguage(std::string));
}


Language.h
Code:
#ifndef LANGUAGE_H
#define LANGUAGE_H
#include <string>
#include <fstream>
#include <map>
#include <sstream>
namespace twile {

    class Language
    {
        public:
            Language();
            void loadLanguage();
            void swapLanguage(std::string to);
            std::string
             getLocalizedString(std::string definer);
        protected:
        private:
            std::ifstream languageFileStream;
            std::string language = "en_US";
            std::map<std::string, std::string> languageSentences;

    };

}

#endif // LANGUAGE_H


and Language.cpp
Code:
#include "Language.h"

using namespace twile;
using namespace std;

Language::Language()
{
    //ctor
}

void Language::loadLanguage() {
    std::string filePath;
    languageFileStream.open(filePath.append("data/locale/").append(language).append("/locale.lang"));
    if(!languageFileStream.is_open()) {
        printf("Error, language file not found!\n");
    }
    std::string line;
    while(std::getline(languageFileStream,line)) {
        int equalPositon = line.find("=");
        std::string key;
        std::string value;
        key = line.substr(0, equalPositon);
        value = line.substr(equalPositon+1);
        languageSentences[key] = value;
    }

    languageFileStream.close();
}

std::string Language::getLocalizedString(std::string definer) {
    return languageSentences[definer];
}

void Language::swapLanguage(std::string to) {
    language = to;
    loadLanguage();
}


What the actual ** is wrong here?
Logged

Makerimages-Its in the pixel
Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #1 on: December 15, 2014, 03:03:22 PM »

Without knowing anything about the libraries you're using, my guess is the unnecessary (std::string) in the method pointer.

Try this instead:

Code:
class_<Language>("Language").def("swapLanguage", &Language::swapLanguage);
Logged



What would John Carmack do?
makerimages
Level 2
**


Makerimages Studios


View Profile WWW
« Reply #2 on: December 16, 2014, 02:33:15 AM »

That eliminates that error, but makes the following pop up instead:

C:\Users\me\Workspace\Dependencies\boost\include\boost\python\object\value_holder.hpp|137|error: use of deleted function 'twile::Language::Language(const twile::Language&)'|

and several errors like taht, reffering to the ifstream constructors and functions :/
Logged

Makerimages-Its in the pixel
Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #3 on: December 16, 2014, 05:38:36 AM »

std::ifstream is non-copyable, and since your class contains one, it becomes non-copyable as well.  Something in that library is trying to copy objects of your class, hence the error.

You'll need to find someone with some experience in that library, I think.  I don't really understand what your class intends to accomplish, but I will say that having a filestream member is highly unusual.

Addendum:  After a second glance at your code, why do you have a std::ifstream member?  Why are you not just declaring one in Language::loadLanguage?  Since you close the file at the end of the function anyway, there's no reason to keep the filestream around.
« Last Edit: December 16, 2014, 05:59:46 AM by Average Software » Logged



What would John Carmack do?
makerimages
Level 2
**


Makerimages Studios


View Profile WWW
« Reply #4 on: December 16, 2014, 06:56:49 AM »

Moving the ifstream into Language::loadLanguage takes care of those erros... and presents me with crptic shitz like:

undefined reference to `_imp___ZN5boost6python6detail11init_moduleEPKcPFvvE' on line 8 of PythonSupport.cpp .. :/

Do I need to compiel PythonSUpport somehow differently? Will it not compile just by running my project? Or is it the case of me trying to make an executable?? SHould this be somehow in a separate place???
« Last Edit: December 16, 2014, 07:36:31 AM by makerimages » Logged

Makerimages-Its in the pixel
Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #5 on: December 16, 2014, 08:58:21 AM »

That's a linker error.  It has nothing to do with your code, but with how you're building the project.  The solution depends on many things, which compiler you're using, which platform, how the library should be linked, and so on.

I can't help with that (like I said earlier, I know nothing about this library) but perhaps someone else can.
Logged



What would John Carmack do?
makerimages
Level 2
**


Makerimages Studios


View Profile WWW
« Reply #6 on: December 16, 2014, 09:47:30 AM »

Ah, nevermind, I just gave boost a trip to the trash Tongue
Logged

Makerimages-Its in the pixel
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic