Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7010791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:02:35+00:00 2026-05-27T22:02:35+00:00

I’ve wandered into the deep end of the pool here. I’ve made some good

  • 0

I’ve wandered into the deep end of the pool here. I’ve made some good progress but now am just thrashing around. I’m trying to use this fuzzy logic lib in iOS: http://code.google.com/p/fuzzy-lite/

I’ve got it to compile – what I did was to add both the .cpp & the .h files to my project and changed the suffix on my main viewController to “.mm”. I am able to run the fuzzyLite test.h file from within viewDidload (show below). It runs and the test data is displayed.

What I need to do is create a persistent instance of fuzzyLite so I can use it in my app (e.g. be able to address it and then clean up when the app unloads).

I’ve searched around but haven’t understood the discussions/examples of including C++ code in an ObjC project. Can someone show me a way I can move forward with this – wrapping the fuzzyLite code so I can call functions and get results back? Thanks!

EDIT: I’ve made progress on this using the method detailed here:
http://robnapier.net/blog/wrapping-c-take-2-1-486

One thing I am unclear on is memory cleanup. The dealloc function cleans up the instance of the wrapped CPP instance – but what about memory alloc’ed within the CCP instance? Seems like I need call a method to release that prior to deleting the instance.

ex: the wrapped class has some instance vars of subclasses- is my cleanup function enough to manage the memory properly?

void Bingo::cleanup(){

delete  engine;
engine = NULL;
delete health;
health = NULL;
delete energy;
energy = NULL;

}

-header for the wrapped CPP class

#include "fuzzylite/FuzzyLite.h"

namespace fl {

class Bingo {
public:
    FuzzyEngine* engine;
    OutputLVar* health;
    InputLVar* energy;
    Bingo();
    void Fuzz();

    void setInput(float input);

};
}

from the ObjC wrapper:

- (void)dealloc
{
delete _cpp;
_cpp = NULL;

[super dealloc];
}

FuzzyLiteIOSViewController.mm

#include "FuzzyLiteIOSViewController.h"
#include "FuzzyLite.h"
#include "test.h"
#include <limits>
#include "fuzzylite/FunctionTerm.h"

//stuff not shown

- (void)viewDidLoad
{
   [super viewDidLoad];

   fl::Test* test = new fl::Test();
   test->SimpleMamdani();

}

test.h

#ifndef FL_TEST_H
#define FL_TEST_H

namespace fl {

class Test {
public:
    static void SimpleMamdani();

};
}


#endif  /* FL_TEST_H */

test.cpp

#include "fuzzylite/test.h"
#include "fuzzylite/FuzzyLite.h"
#include <limits>

#include "fuzzylite/FunctionTerm.h"
namespace fl {

void Test::SimpleMamdani() {
    FuzzyOperator& op = FuzzyOperator::DefaultFuzzyOperator();
    FuzzyEngine engine("simple-mamdani", op);
    engine.hedgeSet().add(new fl::HedgeNot);
    engine.hedgeSet().add(new fl::HedgeSomewhat);
    engine.hedgeSet().add(new fl::HedgeVery);
    fl::InputLVar* energy = new fl::InputLVar("Energy");
    energy->addTerm(new fl::ShoulderTerm("LOW", 0.25, 0.5, true));
    energy->addTerm(new fl::TriangularTerm("MEDIUM", 0.25, 0.75));
    energy->addTerm(new fl::ShoulderTerm("HIGH", 0.50, 0.75, false));
    engine.addInputLVar(energy);

    fl::OutputLVar* health = new fl::OutputLVar("Health");
    health->addTerm(new fl::TriangularTerm("BAD", 0.0, 0.50));
    health->addTerm(new fl::TriangularTerm("REGULAR", 0.25, 0.75));
    health->addTerm(new fl::TriangularTerm("GOOD", 0.50, 1.00));
    engine.addOutputLVar(health);
    fl::RuleBlock* block = new fl::RuleBlock();
    block->addRule(new fl::MamdaniRule("if Energy is LOW then Health is BAD", engine));
    block->addRule(new fl::MamdaniRule("if Energy is MEDIUM then Health is REGULAR", engine));
    block->addRule(new fl::MamdaniRule("if Energy is HIGH then Health is GOOD", engine));
    engine.addRuleBlock(block);

    for (fl::flScalar in = 0.0; in < 1.1; in += 0.1) {
        energy->setInput(in);
        engine.process();
        fl::flScalar out = health->output().defuzzify();
        (void)out; //Just to avoid warning when building
        FL_LOG("Energy=" << in);
        FL_LOG("Energy is " << energy->fuzzify(in));
        FL_LOG("Health=" << out);
        FL_LOG("Health is " << health->fuzzify(out));
        FL_LOG("--");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:02:40+00:00Added an answer on May 27, 2026 at 10:02 pm

    It’s basically not possible to answer your question given the information provided. Your question is about the cleanup method of the Bingo class, but instances of Bingo (either on the stack or the heap) appear nowhere in your code excerpts. Likewise, you state that you are cleaning up a “wrapped CPP instance” but it’s referenced nowhere else. It does appear that you have leaks in your Test::SimplMamdani method — you new a bunch of objects there that don’t [at least in the revealed code] have any corresponding deletes. Similarly, in your FuzzyLiteIOSViewController::viewDidLoad method you create a Test instance on the heap without a corresponding delete. I’m assuming that there’s no autoptr stuff going on under the hood in your C++ code.

    UPDATED to provide additional information:

    Based upon your comment, you need to review the basic language structure of C++. The basic rule is that you’ll need to delete anything that you new. Clean up for the Bingo class should be performed in the destructor (a C++ construct to Objective-C’s dealloc). Your Bingo class should look something more like:

    Bingo.h:

    namespace fl {
        class Bingo {
        public:
    
            Bingo();
            virtual ~Bingo();
    
            void Fuzz();
            void setInput(float input);
    
            FuzzyEngine* engine;
            OutputLVar* health;
            InputLVar* energy;
    
        protected:
        private:
        };
    }
    

    Bingo.cpp:

    using namespace fl;
    
    Bingo::Bingo() {
    }
    
    Bingo::~Bingo() {
        if (engine) {
            delete engine;
        }
        if (health) {
            delete health;
        }
        if (energy) {
            delete energy;
        }
    }
    

    When you delete a Bingo instance, the destructor will be called and Bingo‘s member variables will be disposed.

    Arguably your member variables (engine, health, and energy) should be private in scope and exposed via public-scoped getters and setters.

    Grab a copy of Bjarne Stroustrup’s C++ reference and give it a quick perusal, or use an online get-up-and-going guide like this one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.