/******************************************************************
** Copyright (C) 2001, University of Alabama in Huntsville. 
** All rights reserved.
**
** File   : Rule.cpp
**
** Author : Yangsen Yao
**
** Description:
**    This file provides implementation for the CLIPS Rule
**    class.
**
** History:
**    26-Nov-2001 : Yangsen Yao
**        Created file.
******************************************************************/

#include "Rule.h"
extern "C" 
{
  #include "clips/clips.h"
}

#include <iostream>
#include <string>

// Find for finding the rule
CCLPRule* CCLPRule::Find(std::string ruleName)
{
    void *pDefRule;

    pDefRule = FindDefrule((char*)ruleName.c_str());
    if(pDefRule) {
        CCLPRule *pCCLPRule = new CCLPRule;
        pCCLPRule->pDefRule = pDefRule;
        return pCCLPRule;
    }
    else throw Rule_Not_Found();    
}

// DefRule for executing the command
bool CCLPRule::DefRule()
{
    return this->routecommand();
}

// UnDefRule for removing a defrule from CLIPS
bool CCLPRule::UnDefRule()
{
    return (bool)(Undefrule(this->pDefRule) == 1);
}

// List for printing the list of defrules
void CCLPRule::List()
{
    ListDefrules("stdout", NULL);
}

void CCLPRule::GetRuleList(DATA_OBJECT *returnValue)
{
    // *** FIX THIS ***
	// return GetDefruleList(returnValue, NULL);
}

// NameOf for returning the name of a defrule.
std::string CCLPRule::NameOf()
{
    std::string ruleName;
    ruleName = GetDefruleName(this->pDefRule);
    return ruleName;
}

// IsDeletable for indicating whether or not a particular defrule 
// can be deleted.
bool CCLPRule::IsDeletable()
{
    return (bool)(IsDefruleDeletable(this->pDefRule) == 1);
}
