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

📄 valuefactory.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================//// Author: Bob Blair (bblair@bmc.com)//// Modified By:  Karl Schopmeyer (k.schopmeyer@opengroup.org)//                  Correct Null processing and correct calls to nextcsv - Mar 4 2002//              Carol Ann Krug Graves, Hewlett-Packard Company//                (carolann_graves@hp.com)//              Amit K Arora, IBM (amita@in.ibm.com) for PEP#101//              Ed Boden, IBM (bodeneb@us.ibm.com) for bugzilla 1557, 9/6/2004////%///////////////////////////////////////////////////////////////////////////////// implementation of valueFactory //#include <Pegasus/Common/Config.h>#include <Pegasus/Common/AutoPtr.h>#include "valueFactory.h"#include "objname.h"#include "cimmofParser.h"  /* unfortunately.  Now that valueFactory needs                              to know about cimmofParser, it might as well			      be rolled into it. */#include <cstring>#include <cstdlib>#include <Pegasus/Common/String.h>// put any debug include, I'd say about here#define local_min(a,b) ( a < b ? a : b )#define local_max(a,b) ( a > b ? a : b )/* Fix up a string with embedded comma with extra   escape character and return the result. This is a hack   to get around the problem that arrays having strings   with an embedded comma are treat the embedded comma   as an array item separator.   NOTE: The correct solution is to add a new value factory   funciton for arrays specifically that uses a different   separator on an array of values.   BUG 497 fix, KS Sept 2003*/String valueFactory::stringWComma(String tmp){	//String tmp = *$3;	String rtn = String::EMPTY;	Uint32 len;	while((len = tmp.find(',')) != PEG_NOT_FOUND)	{		rtn.append(tmp.subString(0,len));		rtn.append("\\,");		tmp = tmp.subString(len+1);	}	if (tmp.size() > 0)		rtn.append(tmp);	return(rtn);}longvalueFactory::Stoi(const String &val) {#if 0  unsigned int end = val.size();  String s;  for (unsigned int i = 0; i < end; i++) {    switch(val[i]) {    case '1': s.append("1"); break;    case '2': s.append("2"); break;    case '3': s.append("3"); break;    case '4': s.append("4"); break;    case '5': s.append("5"); break;    case '6': s.append("6"); break;    case '7': s.append("7"); break;    case '8': s.append("8"); break;    case '9': s.append("9"); break;    case '0': s.append("0"); break;    }  }  return atol(s.getCString());#else  long longValue;  if (!sscanf(val.getCString(), "%ld", &longValue))  {//   ATTN-DME-P3-20020602: How should this error condition be handled?     return 0;  }  else return longValue;#endif}static doubleStof(const String &val) {  unsigned int end = val.size();  String s;  for (unsigned int i = 0; i < end; i++) {    switch(val[i]) {    case '1': s.append("1"); break;    case '2': s.append("2"); break;    case '3': s.append("3"); break;    case '4': s.append("4"); break;    case '5': s.append("5"); break;    case '6': s.append("6"); break;    case '7': s.append("7"); break;    case '8': s.append("8"); break;    case '9': s.append("9"); break;    case '0': s.append("0"); break;    case '.': s.append("."); break;    case 'E':    case 'e': s.append("E"); break;    }  }  return atof(s.getCString());}static CIMDateTime &StoDT(const String &val, CIMDateTime &dt) {  unsigned int end = val.size();  String s;  for (unsigned int i = 0; i < end; i++) {    switch(val[i]) {    case '1': s.append("1"); break;    case '2': s.append("2"); break;    case '3': s.append("3"); break;    case '4': s.append("4"); break;    case '5': s.append("5"); break;    case '6': s.append("6"); break;    case '7': s.append("7"); break;    case '8': s.append("8"); break;    case '9': s.append("9"); break;    case '0': s.append("0"); break;    case '.': s.append("."); break;    case '+': s.append("+"); break;    case '-': s.append("-"); break;    case ':': s.append(":"); break;    }  }  if (s != "") {    dt.set (s);  }  return dt;}//-------------------------------------------------------------------------// This is a parser for a comma-separated value String.  It returns one// value per call.  It handles quoted String and depends on the caller to// tell it where the end of the String is.// Returns value in value and return pointing to character after separator // string//-------------------------------------------------------------------------static Uint32nextcsv(const String &csv, int sep, const Uint32 start,        const Uint32 end, String &value){  enum parsestate {INDQUOTE, INSQUOTE, NOTINQUOTE};  value = "";  Uint32 maxend = local_min(csv.size(), end);  Uint32 idx = start;  parsestate state = NOTINQUOTE;  // Change KS 4 March 2002. Change from < to <=. Was dropping last char in string.  // ATTN-RK-P3-071702: Added hack to check for null character because Strings  // were sometimes getting created that included an extra null character.  while (idx <= maxend && csv[idx]) {    char idxchar = csv[idx];    switch (state) {    case NOTINQUOTE:      switch (idxchar) {      case '\\':	state = INSQUOTE;	break;      case '"':	state = INDQUOTE;	break;      default:        if (idxchar == sep)           return idx + 1;        else	  value.append(idxchar);	break;      }      break;    case INSQUOTE:      value.append(idxchar);      state = NOTINQUOTE;      break;    case INDQUOTE:      switch (idxchar) {      case '"':	state = NOTINQUOTE;	break;      default:	value.append(idxchar);	break;      }    }    idx++;  }   // end while  return idx;}//-------------------------------------------------------------------// This builds a reference value from a String via the objname class//-------------------------------------------------------------------staticCIMValue *build_reference_value(const String &rep){  // following 2 lines commented out for bugzilla fix 1557  //objectName oname(rep);             //AutoPtr<CIMObjectPath> ref( cimmofParser::Instance()->newReference(oname));

⌨️ 快捷键说明

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