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

📄 value.cxx

📁 Intel XScale PXA255 引导Linux的Redboot 版bootloader源代码!
💻 CXX
📖 第 1 页 / 共 5 页
字号:
//{{{  Banner                           //============================================================================////      value.cxx////      Implementation of value-related CDL classes.////============================================================================//####COPYRIGHTBEGIN####//                                                                          // ----------------------------------------------------------------------------// Copyright (C) 1999, 2000 Red Hat, Inc.//// This file is part of the eCos host tools.//// This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation; either version 2 of the License, or (at your option) // any later version.// // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for // more details.// // You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.//// ----------------------------------------------------------------------------//                                                                          //####COPYRIGHTEND####//============================================================================//#####DESCRIPTIONBEGIN####//// Author(s):   bartv// Contact(s):  bartv// Date:        1999/07/12// Version:     0.02////####DESCRIPTIONEND####//============================================================================//}}}//{{{  #include's                       // ----------------------------------------------------------------------------#include "cdlconfig.h"// Get the infrastructure types, assertions, tracing and similar// facilities.#include <cyg/infra/cyg_ass.h>#include <cyg/infra/cyg_trac.h>// <cdlcore.hxx> defines everything implemented in this module.// It implicitly supplies <string>, <vector> and <map> because// the class definitions rely on these headers.#include <cdlcore.hxx>//}}}//{{{  Statics                          // ----------------------------------------------------------------------------CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlValue);CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlListValue);CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlValuableBody);//}}}//{{{  CdlSimpleValue class             //{{{  Constructors                     // ----------------------------------------------------------------------------CdlSimpleValue::CdlSimpleValue(){    CYG_REPORT_FUNCNAME("CdlSimpleValue:: default constructor");    CYG_REPORT_FUNCARG1XV(this);    value               = "0";    int_value           = 0;    double_value        = 0.0;    valid_flags         = int_valid | double_valid | string_valid;    format              = CdlValueFormat_Default;    CYG_REPORT_RETURN();}CdlSimpleValue::CdlSimpleValue(std::string val){    CYG_REPORT_FUNCNAME("CdlSimpleValue:: string constructor");    CYG_REPORT_FUNCARG1XV(this);    value               = val;    int_value           = 0;    double_value        = 0.0;    valid_flags         = string_valid;    format              = CdlValueFormat_Default;        CYG_REPORT_RETURN();}CdlSimpleValue::CdlSimpleValue(cdl_int val){    CYG_REPORT_FUNCNAME("CdlSimpleValue:: int constructor");    CYG_REPORT_FUNCARG1XV(this);    value               = "0";    int_value           = val;    double_value        = 0.0;    valid_flags         = int_valid;    format              = CdlValueFormat_Default;        CYG_REPORT_RETURN();}CdlSimpleValue::CdlSimpleValue(double val){    CYG_REPORT_FUNCNAME("CdlSimpleValue:: double constructor");    CYG_REPORT_FUNCARG1XV(this);    value               = "0";    int_value           = 0;    double_value        = val;    valid_flags         = double_valid;    format              = CdlValueFormat_Default;    CYG_REPORT_RETURN();}CdlSimpleValue::CdlSimpleValue(bool val){    CYG_REPORT_FUNCNAME("CdlSimpleValue:: bool constructor");    CYG_REPORT_FUNCARG2XV(this, val);    value               = (val) ? "1" : "0";    int_value           = (val) ? 1 : 0;    double_value        = 0.0;    valid_flags         = string_valid | int_valid;    format              = CdlValueFormat_Default;        CYG_REPORT_RETURN();}CdlSimpleValue::CdlSimpleValue(const CdlSimpleValue& original){    CYG_REPORT_FUNCNAME("CdlSimpleValue:: copy constructor");    CYG_REPORT_FUNCARG2XV(this, &original);    value               = original.value;    int_value           = original.int_value;    double_value        = original.double_value;    valid_flags         = original.valid_flags;    format              = original.format;        CYG_REPORT_RETURN();}//}}}//{{{  Destructor                       // ----------------------------------------------------------------------------CdlSimpleValue::~CdlSimpleValue(){    CYG_REPORT_FUNCNAME("CdlsimpleValue:: destructor");    CYG_REPORT_FUNCARG1XV(this);    value               = "";    int_value           = 0;    double_value        = 0.0;    valid_flags         = 0;    format              = CdlValueFormat_Default;    CYG_REPORT_RETURN();}//}}}//{{{  Assignment operators             // ----------------------------------------------------------------------------CdlSimpleValue&CdlSimpleValue::operator=(const CdlSimpleValue& original){    CYG_REPORT_FUNCNAME("CdlSimpleValue:: assignment operator");    CYG_REPORT_FUNCARG2XV(this, &original);    if (this != &original) {        value           = original.value;        int_value       = original.int_value;        double_value    = original.double_value;        valid_flags     = original.valid_flags;        format          = original.format;    }        CYG_REPORT_RETURN();    return *this;}CdlSimpleValue&CdlSimpleValue::operator=(std::string val){    CYG_REPORT_FUNCNAME("CdlSimpleValue:: string assignment");    CYG_REPORT_FUNCARG1XV(this);    value               = val;    int_value           = 0;    double_value        = 0.0;    valid_flags         = string_valid;    format              = CdlValueFormat_Default;    CYG_REPORT_RETURN();    return *this;}CdlSimpleValue&CdlSimpleValue::operator=(cdl_int val){    CYG_REPORT_FUNCNAME("CdlSimpleValue:: integer assignment");    CYG_REPORT_FUNCARG1XV(this);    value               = "";    int_value           = val;    double_value        = 0.0;    valid_flags         = int_valid;    format              = CdlValueFormat_Default;        CYG_REPORT_RETURN();    return *this;}CdlSimpleValue&CdlSimpleValue::operator=(double val){    CYG_REPORT_FUNCNAME("CdlSimpleValue:: double assignment");    CYG_REPORT_FUNCARG1XV(this);    value               = "";    int_value           = 0;    double_value        = val;    valid_flags         = double_valid;    format              = CdlValueFormat_Default;    CYG_REPORT_RETURN();    return *this;}// ----------------------------------------------------------------------------// Converting a boolean into a simple value. This is sufficiently common// to warrant its own member function, and in addition it avoids// ambiguity when assigning 0.CdlSimpleValue&CdlSimpleValue::operator=(bool val){    CYG_REPORT_FUNCNAME("CdlSimpleValue:: bool assignment");    CYG_REPORT_FUNCARG1XV(this);    value               = (val) ? "1" : "0";    int_value           = (val) ? 1 : 0;    double_value        = 0.0;    valid_flags         = string_valid | int_valid;    format              = CdlValueFormat_Default;    CYG_REPORT_RETURN();    return *this;}//}}}//{{{  CdlValuable -> CdlSimpleValue    // ----------------------------------------------------------------------------// This routine bridges the gap between the full data held in the CdlValuable// object and the basic information needed for expression evaluation.voidCdlSimpleValue::eval_valuable(CdlEvalContext& context, CdlValuable valuable, CdlSimpleValue& result){    CYG_REPORT_FUNCNAME("CdlSimpleValue:: valuable assignment");    CYG_REPORT_FUNCARG3XV(&context, valuable, &result);    CYG_PRECONDITION_CLASSC(valuable);    // If the valuable is not currently active then its value is    // always zero for the purposes of expression evaluation.    // FIXME: this check should be on a per-transaction basis.    if (((0 != context.transaction) && !context.transaction->is_active(valuable)) ||        ((0 == context.transaction) && !valuable->is_active())) {                result.value           = "0";        result.int_value       = 0;        result.double_value    = 0.0;        result.valid_flags     = string_valid | int_valid;        result.format          = CdlValueFormat_Default;        CYG_REPORT_RETURN();        return;    }    // Get hold of the underlying CdlValue object    const CdlValue& val = (0 != context.transaction) ?        context.transaction->get_whole_value(valuable) : valuable->get_whole_value();            // Otherwise the value depends on the flavor.    switch(val.get_flavor()) {      case CdlValueFlavor_None :      {        // This could be treated as an error, but since valuables with flavor        // none are permanently enabled a constant "1" is a better result.        result.value           = "1";        result.int_value       = 1;        result.double_value    = 0.0;        result.valid_flags     = string_valid | int_valid;        result.format          = CdlValueFormat_Default;        break;      }      case CdlValueFlavor_Bool :      {        bool enabled           = val.is_enabled();        result.value           = (enabled) ? "1" : "0";        result.int_value       = (enabled) ?  1  :  0;        result.double_value    = 0.0;        result.valid_flags     = string_valid | int_valid;        result.format          = CdlValueFormat_Default;        break;      }      case CdlValueFlavor_BoolData :      {        if (!val.is_enabled()) {                                result.value        = "0";            result.int_value    = 0;            result.double_value = 0.0;            result.valid_flags  = string_valid | int_valid;            result.format       = CdlValueFormat_Default;                            } else {            // Just use a copy constructor, let the compiler optimise things.            result = val.get_simple_value();        }        break;      }      case CdlValueFlavor_Data :      {        // Just like BoolData, but with no need to check the enabled flag.        result = val.get_simple_value();        break;      }      default:      {        CYG_FAIL("Valuable object with an unknown flavor encountered.");      }    }    CYG_REPORT_RETURN();}//}}}//{{{  Getting the value                // ----------------------------------------------------------------------------// Some of these calls involve conversion operators.std::stringCdlSimpleValue::get_value() const{    CYG_REPORT_FUNCNAME("CdlSimpleValue::get_value");    CYG_REPORT_FUNCARG1XV(this);    if (!(valid_flags & string_valid)) {        if (valid_flags & int_valid) {            Cdl::integer_to_string(int_value, value, format);        } else if (valid_flags & double_valid) {            Cdl::double_to_string(double_value, value, format);        } else {            CYG_FAIL("Attempt to use uninitialized SimpleValue");        }        valid_flags |= string_valid;    }    CYG_REPORT_RETURN();    return value;}boolCdlSimpleValue::has_integer_value() const{    CYG_REPORT_FUNCNAMETYPE("CdlSimpleValue::has_integer_value", "result %d");    CYG_REPORT_FUNCARG1XV(this);    if (!(valid_flags & (int_valid | int_invalid))) {        if (valid_flags & double_valid) {            if (Cdl::double_to_integer(double_value, int_value)) {                valid_flags |= int_valid;            } else {                valid_flags |= int_invalid;            }        } else if (valid_flags & string_valid) {            if (Cdl::string_to_integer(value, int_value)) {                valid_flags |= int_valid;            } else {                valid_flags |= int_invalid;            }        } else {            CYG_FAIL("Attempt to use uninitialized SimpleValue");        }    }        bool result = (valid_flags & int_valid);    CYG_REPORT_RETVAL(result);    return result;}cdl_intCdlSimpleValue::get_integer_value() const{    CYG_REPORT_FUNCNAMETYPE("CdlsimpleValue::get_integer_value", "result %ld");

⌨️ 快捷键说明

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