⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ie.cpp

📁 很好的windows驱动开发书记,基于WDM的,,可以很好的学习
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		}
	}

	// excute main goal update, unless rule fired
    if ( ! ruleFired )
    {
	    m_curGoal->update();
    }
    // go ahead and check finish this frame to possibly be ready for the next
    else
    {
        checkFinish();
    }

    if ( dbg ) printf ( "Goal %s updated.\n", m_curGoal->getName() );
}

//===========================================================================
// Name: 
// checkStart 
//
// Description: 
// Checks for start condition and performs start if it needs to.
//
// Parameters: 
// None.
//
// Return Value: 
// None.
//
// Remarks: 
//
//===========================================================================
void IE::checkStart ()
{
	if ( m_curGoal->atStart() )
	{
		// call start
		m_curGoal->start();

        m_curGoal->setStart ( false );

        if ( dbg ) printf ( "Goal %s start.\n", m_curGoal->getName() );

        m_curGoal->resetFiredRules();
	}
}

//===========================================================================
// Name: 
// checkFinish 
//
// Description: 
// Checks for finish condition
//
// Parameters: 
// None.
//
// Return Value: 
// Returns false if not finished, else true.
//
// Remarks: 
//
//===========================================================================
bool IE::checkFinish ()
{
	if ( m_curGoal->atFinish() )
	{
        if ( dbg ) printf ( "Goal %s at finish.\n", m_curGoal->getName() );

		// call finish method, if not finished
		// then return and process no more
		if ( m_curGoal->finish() == false )
        {
            if ( dbg ) printf ( "Goal %s net yet finished.\n", m_curGoal->getName() );
			return false;
        }

		// goal is finished, reset it
		m_curGoal->reset();

        // set last goal of next goal so it will know who 
        // transferred control to it
        m_nextGoal->m_lastGoal = m_curGoal;

        if ( dbg ) printf ( "Goal %s finished.\n", m_curGoal->getName() );

		// prepare next goal
		m_curGoal = m_nextGoal;

		// push new goal on stack, or if it is already
        // on the stack then simply set the stack to it
		pushGoal ( m_curGoal );	
	}

    return true;
}

//===========================================================================
// Name: 
// noRule 
//
// Description: 
// Tests for a current rule and prints error info if there is not one.
//
// Parameters: 
// lineInfo - Debug info about the current line of a macro.
//
// Return Value: 
// True if there is no current rule. False otherwise.
//
// Remarks: 
//
//===========================================================================
bool IE::noRule ( char * lineInfo )
{
    if ( ! m_curRule )
    {
        printf ( "ERROR: No rule specified at %s.\n", lineInfo );
        return true;
    }

    return false;
}

//===========================================================================
// Name: 
// linkRuleGoals 
//
// Description: 
// Links rules with the goals they are referencing via name. 
//
// Parameters: 
// None.
//
// Return Value: 
// None.
//
// Remarks: 
// If a rule refers to a goal that is not found then error info is printed
// about the line the rule macro was on.
//===========================================================================
void IE::linkRuleGoals ()
{
    std::list<IEGoal *>::iterator goalItr;
    std::list<IERule *>::iterator ruleItr;

    IEGoal * goal;
    IERule * rule;

    goalItr = m_goalList.begin();

    // iterate through goals
    while ( goalItr != m_goalList.end() )
    {
        goal = *goalItr++;

        // for every rule in the goal
        ruleItr = goal->m_rules.begin();

        while ( ruleItr != goal->m_rules.end() )
        {
            rule = *ruleItr++;

            // if there is a goal name then find it
            if ( rule->m_goalName.length() > 0 )
            {
                IEGoal * ruleGoal = findGoal ( rule->m_goalName );

                if ( ruleGoal == NULL )
                {
                    printf ( "ERROR: Goal %s at %s does not exist.\n",
                        rule->m_goalName, rule->m_lineInfo );                    
                }
                else
                {
                    rule->setGoal ( ruleGoal );
                }
            }
        }
    }
}

//===========================================================================
// Name: 
// findGoal 
//
// Description: 
// Finds a goal in the goal list given a name.
//
// Parameters: 
// goalName - The name of the goal being searched for.
//
// Return Value: 
// A pointer to the found goal or NULL.
//
// Remarks: 
//
//===========================================================================
IEGoal * IE::findGoal ( std::string & goalName )
{
    std::list<IEGoal *>::iterator goalItr;

    IEGoal * goal;

    goalItr = m_goalList.begin();

    while ( goalItr != m_goalList.end() )
    {
        goal = *goalItr;

        if ( goal->m_name == goalName )
            return goal;

        ++goalItr;
    }

    return NULL;
}

//===========================================================================
// Name: 
// pushGoal 
//
// Description: 
// Pushes a goal onto the goal stack, but first looks to see if it is already
// on the stack and pops everybody above it if it is.
//
// Parameters: 
// addGoal - The goal to put on the top of the stack.
//
// Return Value: 
// None.
//
// Remarks: 
//
//===========================================================================
void IE::pushGoal ( IEGoal * addGoal )
{
    std::list<IEGoal *>::iterator goalItr;

    IEGoal * goal;

    // first, see if goal alread on the stack
    goalItr = m_goalStack.begin();

    while ( goalItr != m_goalStack.end() )
    {
        goal = *goalItr;

        // if found
        if ( goal == addGoal )
        {
            goalItr = m_goalStack.end();

            --goalItr;

            // pop stack off above goal
            while ( goal != *goalItr )
            {
                m_goalStack.pop_back ();

                --goalItr;
            }

            // done, quit
            return;
        }

        ++goalItr;
    }

    // not on stack so put it there
    m_goalStack.push_back ( addGoal );
}

//===========================================================================
// Name: 
// popGoal  
//
// Description: 
// Pops a goal and every goal above it off the stack.
//
// Parameters: 
// goal - The goal to take off the stack.
//
// Return Value: 
// None.
//
// Remarks: 
//
//===========================================================================
void IE::popGoal  ( IEGoal * goal2Pop )
{
    std::list<IEGoal *>::iterator goalItr;

    IEGoal * goal;

    goalItr = m_goalStack.end();

    --goalItr;

    // pop upto and including goal2Pop
    while ( !m_goalStack.empty() )
    {
        goal = *goalItr--;

        m_goalStack.pop_back();

        // quit if at goal2Pop
        if ( goal == goal2Pop )
            return;
    }

    // shouldn't reach here
    printf ( "ERROR: Goal %s does not exsit on the goal stack.\n",
        goal2Pop->getName() );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -