コード例 #1
0
ファイル: JtagTypes.cpp プロジェクト: blargony/RFFEAnalyzer
std::string JtagShiftedData::GetDecimalString(const std::vector<U8>& bits)
{
	std::string ret_val("0");
	std::vector<U8>::const_iterator bi(bits.begin());
	int carry, digit;
	while (bi != bits.end())
	{
		carry = *bi ? 1 : 0;		

		// multiply ret_val by 2 and add the carry bit
		std::string::reverse_iterator ai(ret_val.rbegin());
		while (ai != ret_val.rend())
		{
			digit = (*ai - '0') * 2 + carry;
			*ai = (digit % 10) + '0';
			carry = digit / 10;

			++ai;
		}

		if (carry > 0)
			ret_val = char(carry + '0') + ret_val;

		++bi;
	}

	return ret_val;
}
コード例 #2
0
ファイル: tcli.c プロジェクト: UlricE/SiagOffice
static int sum(ClientData clientdata, Tcl_Interp *interp,
			Tcl_Value *args, Tcl_Value *resultPtr)
{
	double sum;
	int r, c, startr, startc, endr, endc;
	startr = args[0].intValue;
	startc = args[1].intValue;
	endr = args[2].intValue;
	endc = args[3].intValue;
	if (startr > endr) {
		r = startr;
		startr = endr;
		endr = r;
	}
	if (startc > endc) {
		c = startc;
		startc = endc;
		endc = c;
	}
	sum = 0;
	for (r = startr; r <= endr; r++)
		for (c = startc; c <= endc; c++)
			sum += ret_val(siag_buffer, siag_sht, r, c).number;
	resultPtr->doubleValue = sum;
	resultPtr->type = TCL_DOUBLE;
	return TCL_OK;
}
コード例 #3
0
ファイル: siodi.c プロジェクト: UlricE/SiagOffice
static LISP x_get_cell(LISP row, LISP col, LISP bname)
{
	int r, c;
	char *p;
	buffer *buf;
	int s;

	r = get_c_long(row);
	c = get_c_long(col);
	if (r < 1 || r > BUFFER_ROWS || c < 1 || c > BUFFER_COLS)
		return NIL;
	if (NULLP(bname)) {
		buf = siag_buffer;
		s = siag_sht;
	} else if (TYPEP(bname, tc_string)) {
		buf = find_sheet_by_name(bname->storage_as.string.data,
					siag_buffer, &s);
		if (buf == NULL) return NIL;
	}
	else return NIL;

	switch (ret_type(buf, s, r, c)) {
	case STRING:
		p = ret_string(buf, s, r, c);
		return strcons(strlen(p), p);
	case LABEL:
		p = ret_text(buf, s, r, c);
		return strcons(strlen(p), p);
	case EMPTY:
	case ERROR:
		return NIL;
	default:
		return flocons(ret_val(buf, s, r, c).number);
	}
}
コード例 #4
0
ファイル: reflector.hpp プロジェクト: fast01/jrtti
	/**
	 * \brief Removes type name decorators
	 *
	 * This is a utility method to get human readable type names. It is used by
	 * Metatype::name method and you can use to compare typenames.
	 * The results of typeid().name() depend compiler implementations. Therefore
	 * there is not a general rule to demangle such results. jrtti::demangle
	 * implementation manages GNU gcc++, MSC++ and Borland C++ compilers. If your
	 * compiler is not on the list, it could still work. If not try to use
	 * jrtti::registerPrefixDecorator to try to suit your compiler implementation.
	 * \param name the name to demangle
	 * \return the demangled name
	 * \sa registerPrefixDecorator
	 */
	std::string
	demangle( const std::string& name ) {
#ifdef __GNUG__
		int status = -4;
		char* res = abi::__cxa_demangle(name.c_str(), NULL, NULL, &status);
		const char* const demangled_name = (status==0)?res:name.c_str();
		std::string ret_val(demangled_name);
		free(res);
		return ret_val;
#elif __BORLANDC__
		return name;
#else
		for ( std::vector< std::string >::iterator it = m_prefixDecorators.begin(); it != m_prefixDecorators.end(); ++it ) {
			size_t pos = name.find( *it );
			if ( pos != std::string::npos ) {
				pos += it->length() + 1;
				return name.substr( pos );
			}
		}
		return name;
	#ifndef _MSC_VER
		#warning "Your compiler may not support demangleing of typeid(T).name() results. See jrtti::demangle documentation"
	#endif
#endif
	}
コード例 #5
0
ファイル: all_inter.c プロジェクト: NSSX/ray
double		inter_sphere(t_obj *obj, t_env *e)
{
	t_vec3d		eye_origin;
	double		a;
	double		b;
	double		c;
	double		det;
	t_vec3d		ray_dir;


	ray_dir = (t_vec3d){e->ray_dir.x,e->ray_dir.y,e->ray_dir.z};
	eye_origin = eye_or(e->ray_origin, obj->pos);
	rotate_x(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
			-obj->rot.x);
	rotate_y(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
			-obj->rot.y);
	rotate_z(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
			-obj->rot.z);
	rotate_x(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z),
			-obj->rot.x);
	rotate_y(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z),
			-obj->rot.y);
	rotate_z(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z), -obj->rot.z);
	a = mult(&(ray_dir), &(ray_dir));
	b = mult(&eye_origin, &(ray_dir));
	c = mult(&eye_origin, &eye_origin) - obj->size * obj->size;
	det = b * b - a * c;
	if (det < 0.0001)
		return (-1);
	return (ret_val(a,b,det));
}
コード例 #6
0
  int dft_linprobmgr_setrhs(void * linprobmgr, double** x) {
    BLPM * linprobmgr_ = (BLPM *) linprobmgr;
    int numOwnedNodes = linprobmgr_->getNumOwnedNodes();
    int numUnknownsPerNode = linprobmgr_->getNumUnknownsPerNode();

    SCALAR **fx;
    fx = new SCALAR*[numUnknownsPerNode];
    for (int i=0; i<numUnknownsPerNode;i++)
      fx[i] = new SCALAR[numOwnedNodes];
    for(int i=0;i<numUnknownsPerNode;i++)
      for(int j=0;j<numOwnedNodes;j++)
	fx[i][j] = x[i][j];

    Array<ArrayView<const SCALAR> > my_x(numUnknownsPerNode);
    for(int i = 0; i < numUnknownsPerNode; i++){
      my_x[i] = ArrayView<const SCALAR>(fx[i], numOwnedNodes);
    }
    ArrayView<ArrayView<const SCALAR> > ret_val(my_x());
    linprobmgr_->setRhs(ret_val);
    for (int i = 0; i < numUnknownsPerNode; ++i)
      delete [] fx[i];
    delete [] fx;

    return( 0 );
  }
コード例 #7
0
ファイル: all_inter.c プロジェクト: NSSX/ray
double		inter_cyl(t_obj *obj, t_env *e)
{
	t_vec3d  eye_origin;
	double  a;
	double  b;
	double  c;
	double  det;
	double angle = 90;
	t_vec3d ray_dir;


	ray_dir = (t_vec3d){e->ray_dir.x,e->ray_dir.y,e->ray_dir.z}; 
	eye_origin = eye_or(e->ray_origin, obj->pos);
	rotate_x(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
			-obj->rot.x);
	rotate_y(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
			-obj->rot.y);
	rotate_z(&(eye_origin.x), &(eye_origin.y), &(eye_origin.z),
			-obj->rot.z);
	rotate_x(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z),
			-obj->rot.x);
	rotate_y(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z),
			-obj->rot.y);
	rotate_z(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z), -obj->rot.z);
	a = ray_dir.x * ray_dir.x + ray_dir.z * ray_dir.z;
	b = ray_dir.x * eye_origin.x + ray_dir.z * eye_origin.z;
	c = eye_origin.x * eye_origin.x + eye_origin.z * eye_origin.z - obj->size * obj->size;
	det = b * b - a * c;
	if (det < 0.0001)
		return (-1);
	return (ret_val(a,b,det));
}
コード例 #8
0
/**
 * Reads the commanded azimuth from Mount2 telescope.
 *
 */
CORBA::Double Mount2RefAzDevIO::read(ACS::Time& timestamp) throw (ACSErr::ACSbaseExImpl)
{
	ACS_SHORT_LOG( (LM_INFO, "Mount2RefAzDevIO: read"));
	CORBA::Double ret_val(0.0);
//	char *msg;
//	unsigned long read_alt, read_azm;
//	CORBA::Double azm;

	Communication comm = Communication("/dev/ttyUSB0");
	ret_val = comm.getAzm();
//	SerialRS232 *sp = new SerialRS232("/dev/ttyUSB0");
//	sp->write_RS232("z");
//	msg = sp->read_RS232();
//	sscanf(msg,"%08lX,%08lX#",&read_azm,&read_alt);
//
//#define MAX_PRECISE_ROTATION 4294967296.0
//
//	azm = (double)read_azm / MAX_PRECISE_ROTATION;
//	azm *= 360.0;
//
//	ret_val = azm;
//
//	timestamp=getTimeStamp();
//	delete sp;
	return ret_val;
}
コード例 #9
0
std::string OutBuffer::Front()
{
	boost::mutex::scoped_lock lock(buffer_mutex);
	std::string ret_val(buffer.front());
	buffer.pop_front();
	return std::move(ret_val);
}
コード例 #10
0
//--------------------------------------------------------------------------------------
// use faster implementations in subclasses, if you prefer
std::string ImplAlignandum::asString() const
{
	std::string ret_val("");

	for (Position i = 0; i < mLength; i++)
		ret_val += getToolkit()->getEncoder()->decode( asResidue(i) );

	return ret_val;
}
コード例 #11
0
ファイル: siodi.c プロジェクト: UlricE/SiagOffice
/*
;@siag_colsum(c1, c2)
;@Returns the sum of all cells on the current row from column c1 to c2.
;@
;@siag_rowsum
*/
static LISP lsiag_colsum(LISP c1, LISP c2)
{
	double sum = 0;
	int i;
	long tmp = get_c_long(c2);
	for (i = get_c_long(c1); i <= tmp; i++)
		sum += ret_val(siag_buffer, siag_sht, siag_row, i).number;
	return flocons(sum);
}
コード例 #12
0
ファイル: op_components.C プロジェクト: junyang4711/Block
  template<> std::vector<std::vector<int> > Op_component<CreDesDesComp>::get_array() const 
    {
      std::vector<int> orbs(1);
      std::vector< std::vector<int> > ret_val(m_op.local_nnz());
      for (int i=0; i<m_op.local_nnz(); i++)
	{
	  orbs[0] = m_op.get_local_indices()[i];
	  ret_val[i] = orbs;
	}
      return ret_val;
    }
コード例 #13
0
ファイル: siodi.c プロジェクト: UlricE/SiagOffice
static double ret_number(buffer *buf, int s, int r, int c)
{
	if (r < 1 || r > BUFFER_ROWS || c < 1 || c > BUFFER_COLS) return 0.0;
	switch (ret_type(buf, s, r, c)) {
	case STRING:
	case LABEL:
	case EMPTY:
	case ERROR:
		return 0;
	default:
		return ret_val(buf, s, r, c).number;
	}
}
コード例 #14
0
ファイル: demangle.cpp プロジェクト: larry-fuy/labs-c11
const std::string demangle(const char* name) {

    int status = -4;

    char* res = abi::__cxa_demangle(name, NULL, NULL, &status);

    const char* const demangled_name = (status==0)?res:name;

    std::string ret_val(demangled_name);

    free(res);

    return ret_val;
}
コード例 #15
0
IntVector<NDIM> INSCollocatedVelocityBcCoef::numberOfExtensionsFillable() const
{
#if !defined(NDEBUG)
    for (unsigned int d = 0; d < NDIM; ++d)
    {
        TBOX_ASSERT(d_bc_coefs[d]);
    }
#endif
    IntVector<NDIM> ret_val(std::numeric_limits<int>::max());
    for (unsigned int d = 0; d < NDIM; ++d)
    {
        ret_val = IntVector<NDIM>::min(ret_val, d_bc_coefs[d]->numberOfExtensionsFillable());
    }
    return ret_val;
} // numberOfExtensionsFillable
コード例 #16
0
ファイル: tcli.c プロジェクト: UlricE/SiagOffice
static int get_cell(ClientData clientdata, Tcl_Interp *interp,
			Tcl_Value *args, Tcl_Value *resultPtr)
{
	int r = args[0].intValue;
	int c = args[1].intValue;
	int type = ret_type(siag_buffer, siag_sht, r, c);

	if (IS_NUMBER(type))
		resultPtr->doubleValue = ret_val(siag_buffer,
						siag_sht, r, c).number;
		else resultPtr->doubleValue = 0;

	resultPtr->type = TCL_DOUBLE;
	return TCL_OK;
}
コード例 #17
0
ファイル: my_win.cpp プロジェクト: nodep/wht
std::wstring GetExePath()
{
	wchar_t full_exe_name[MAX_PATH];
	size_t name_length = GetModuleFileName(NULL, full_exe_name, MAX_PATH);

	std::wstring ret_val(full_exe_name);

	size_t ndx = ret_val.rfind(L'\\');
	if (ndx != std::wstring::npos)
		ret_val = ret_val.substr(0, ndx + 1);
	else
		ret_val.clear();

	return ret_val;
}
コード例 #18
0
ファイル: ccmath.c プロジェクト: UlricE/SiagOffice
/* the problem here is that we don't know the current buffer
   and current sheet. That information is static in siodi.c
*/
static double get_value(buffer *buf, int sheet, int row, int col)
{
	if (row < 1 || row > BUFFER_ROWS || col < 1 || col > BUFFER_COLS)
		return 0.0;

	switch (ret_type(buf, sheet, row, col)) {
	case STRING:
	case LABEL:
		return strtod(ret_string(buf, sheet, row, col), NULL);
	case EMPTY:
	case ERROR:
		return 0.0;
	default:
		return ret_val(buf, sheet, row, col).number;
	}
}
コード例 #19
0
 //////////////////////////////////////////////////////////////////////
 //  get exit state by tracejob through ssh
 //   --- parse the results of "ssh server_host tracejob jobid"
 //
 std::string ssh::tracejob_get_exit_state(std::string id, std::string svr_name, std::ostringstream& os)
 {
   std::string ret_val("");
 
   try {
   
     bp::command_line cl(command);
     cl.argument(svr_name);
     cl.argument("tracejob");
     cl.argument(id);
 
     bp::launcher l;
     l.set_stdout_behavior(bp::redirect_stream);
     l.set_stderr_behavior(bp::redirect_stream);
 
     bp::child c = l.start(cl);
 
     bp::pistream& stdout = c.get_stdout();
 
     // Find Exit_status
     std::string exit_state;
     boost::regex r("(Exit_status=)(\\d+)");
     boost::smatch results;
     std::string line;
     while ( std::getline(stdout, line)) {
       boost::regex_search(line, results, r);
       if (!results.str().empty()){
         exit_state = results.str(2);
       }
     }
     stdout.close();
 
     bp::status s = c.wait();
     if (s.exited() && s.exit_status() == EXIT_SUCCESS) {
       //std::cout << "exit_state = " << exit_state << std::endl;
       ret_val = exit_state;
     } else {
       //std::cout << "exit_state is empty..." << exit_state << std::endl;
       error_handling(c.get_stderr(), os);
       ret_val = "";
     }
   }
   catch(std::exception const &e) {
     SAGA_ADAPTOR_THROW_NO_CONTEXT(e.what(), saga::NoSuccess);
   }
   return ret_val;
 }
コード例 #20
0
ファイル: hiddev.cpp プロジェクト: nodep/nrfburn
std::string GetErrorString(int error)
{
	LPVOID lpMsgBuf;

	FormatMessage(	FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
					NULL,
					error,
					MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
					(LPTSTR) &lpMsgBuf,
					0,
					NULL);

	std::string ret_val((char*)lpMsgBuf);

	LocalFree(lpMsgBuf);

	return ret_val;
}
コード例 #21
0
ファイル: login_socket.cpp プロジェクト: nonametr/anima
string LoginSocket::statReq(string &data)
{
    string secret 	= getParam(data, "secret");
    string commit_user  = getParam(data, "commit_user");
    string uid 		= getParam(data, "uid");

    if (secret != "power")
    {
        traceerr("Access denied! secret rq = %s", secret.c_str());
        return "";
    }

    uint time = iStorage->getCurrentTime();
    uint users_count = iStorage->getLocalUsersCount();
    string ret_val("");
    char buf[2048] = {"\0"};
    snprintf(buf, 2048,  "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"\
/><title>Статистика</title></head><body>Статистика:<br>Время: %u; <br>Онлайн: %u;", time, users_count);
コード例 #22
0
ファイル: rope_piece.cpp プロジェクト: acumiobill/Acumio
std::string RopePiece::ToString() const {
  if (string_ != nullptr) {
    return std::string(string_);
  }

  if (prefix_ == nullptr) {
    if (suffix_ == nullptr) {
      return std::string();
    }
    return suffix_->ToString();
  }

  if (suffix_ == nullptr) {
    return prefix_->ToString();
  }

  char* buffer = new char[length_ + 1];
  CopyToBuffer(buffer);
  std::string ret_val(buffer);
  delete [] buffer;
  return ret_val;
}
コード例 #23
0
ファイル: all_inter.c プロジェクト: NSSX/rkt
double		inter_cone(t_obj *obj, t_env *e)
{
	t_vec3d		eo;
	double		a;
	double		b;
	double		c;
	t_vec3d		ray_dir;

	ray_dir = (t_vec3d){e->ray_dir.x, e->ray_dir.y, e->ray_dir.z};
	eo = eye_or(e->ray_origin, obj->pos);
	rotate_x(&(eo.x), &(eo.y), &(eo.z), -obj->rot.x);
	rotate_y(&(eo.x), &(eo.y), &(eo.z), -obj->rot.y);
	rotate_z(&(eo.x), &(eo.y), &(eo.z), -obj->rot.z);
	rotate_x(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z), -obj->rot.x);
	rotate_y(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z), -obj->rot.y);
	rotate_z(&(ray_dir.x), &(ray_dir.y), &(ray_dir.z), -obj->rot.z);
	a = ray_dir.x * ray_dir.x - ray_dir.y * ray_dir.y + ray_dir.z * ray_dir.z;
	b = ray_dir.x * eo.x - ray_dir.y * eo.y + ray_dir.z * eo.z;
	c = eo.x * eo.x + eo.z * eo.z - eo.y * eo.y;
	e->det = b * b - a * c;
	if (e->det < 0.0001)
		return (-1);
	return (ret_val(a, b, e->det));
}
コード例 #24
0
ファイル: siodi.c プロジェクト: UlricE/SiagOffice
static LISP siag_sum(LISP start, LISP end)
{
	double sum;
	int r, c, startr, startc, endr, endc;
	startr = get_c_long(car(start));
	startc = get_c_long(cdr(start));
	endr = get_c_long(car(end));
	endc = get_c_long(cdr(end));
	if (startr > endr) {
		r = startr;
		startr = endr;
		endr = r;
	}
	if (startc > endc) {
		c = startc;
		startc = endc;
		endc = c;
	}
	sum = 0;
	for (r = startr; r <= endr; r++)
		for (c = startc; c <= endc; c++)
			sum += ret_val(siag_buffer, siag_sht, r, c).number;
	return flocons(sum);
}
コード例 #25
0
ファイル: uart.hpp プロジェクト: emutex/mraa
 /**
  * Get string with tty device path within Linux
  * For example. Could point to "/dev/ttyS0"
  *
  * @return char pointer of device path
  */
 std::string
 getDevicePath()
 {
     std::string ret_val(mraa_uart_get_dev_path(m_uart));
     return ret_val;
 }
コード例 #26
0
bool gauss(const std::vector<std::vector<double> >& input, std::vector<double>& ans, size_t num_of_threads)
{
	std::vector<std::vector<double> > a = input;
	cyclic_barrier barrier(num_of_threads);
	size_t n = a.size();
	std::vector<size_t> parallel_max_row(num_of_threads);
	std::vector<bool> ret_val(num_of_threads, true);
	std::vector<std::thread> threads;
	threads_guard guard(threads);
	size_t max_row;
	size_t row = 0;
	std::vector<int> base(n, -1);
	for (size_t i = 0; i < num_of_threads; ++i)
	{
		threads.emplace_back([&, i]
		{
			for (size_t column = 0; column < n; ++column)
			{
				while (column < n)
				{
					parallel_max_row[i] = row;
					for (size_t cur_row = get_start_index_for_cyclic_partition(row, i, num_of_threads); cur_row < n; cur_row += num_of_threads)
					{
						if (std::abs(a[parallel_max_row[i]][column]) < std::abs(a[cur_row][column]))
						{
							parallel_max_row[i] = cur_row;
						}
					}
					barrier.enter();
					if (i == 0)
					{
						if (column == n)
						{
							column++;
							break;
						}
						max_row = parallel_max_row[0];
						for (size_t j = 1; j < num_of_threads; ++j)
						{
							if (a[max_row][column] < a[parallel_max_row[j]][column])
							{
								max_row = parallel_max_row[j];
							}
						}
					}
					barrier.enter();
					if (std::abs(a[max_row][column++]) >= EPS)
					{
						break;
					}
					if (column == n)
					{
						column++;
						break;
					}
				}
				column--;
				if (column == n)
				{
					for (size_t cur_row = get_start_index_for_cyclic_partition(row, i, num_of_threads); cur_row < n; cur_row += num_of_threads)
					{
						if (std::abs(a[cur_row][n]) >= EPS)
						{
							ret_val[i] = false;
							return;
						}
					}
					break;
				}
				if (max_row != row)
				{
					for (size_t index = get_start_index_for_cyclic_partition(column, i, num_of_threads); index <= n; index += num_of_threads)
					{
						std::swap(a[max_row][index], a[row][index]);
					}
				}
				barrier.enter();
				for (size_t cur_row = i; cur_row < n; cur_row += num_of_threads)
				{
					if (cur_row == row)
					{
						continue;
					}
					double coef = a[cur_row][column] / a[row][column];
					for (size_t index = column; index <= n; ++index)
					{
						a[cur_row][index] -= a[row][index] * coef;
					}
				}
				barrier.enter();
				for (size_t index = get_start_index_for_cyclic_partition(column + 1, i, num_of_threads); index <= n; index += num_of_threads)
				{
					a[row][index] /= a[row][column];
				}
				barrier.enter();
				if (i == 0)
				{
					base[column] = row;
					a[row][column] = 1.0;
					++row;
				}
				barrier.enter();
			}
			for (size_t column = i; column < n; column += num_of_threads)
			{
				if (base[column] != -1)
				{
					ans[column] = a[base[column]][n];
				}
			}
		});
	}
	for (auto& it : threads)
	{
		it.join();
	}
	for (auto it : ret_val)
	{
		if (!it)
		{
			return false;
		}
	}
	return true;
}
コード例 #27
0
ファイル: SMALLCHAR.cpp プロジェクト: fnasim/smadsql
	//CONVERSION FUNCTIONS
	SMADSMALLCHAR::operator SMADDOUBLE(){
		SMADDOUBLE ret_val(atof(data.c_str()));
		return ret_val;
		}   
コード例 #28
0
ファイル: test_client.cpp プロジェクト: acumiobill/Acumio
 std::unique_ptr<Server::StubInterface> NewStub(
     const std::shared_ptr<::grpc::ChannelInterface>& channel) {
     std::unique_ptr<Server::StubInterface> ret_val(
         new acumio::model::server::MockServerStub());
     return ret_val;
 }
コード例 #29
0
ファイル: SMALLCHAR.cpp プロジェクト: fnasim/smadsql
	SMADSMALLCHAR::operator SMADINTEGER(){
		SMADINTEGER ret_val(atol(data.c_str()));
		return ret_val;
		}
コード例 #30
0
ファイル: pgsString.cpp プロジェクト: Joe-xXx/pgadmin3
pgsRecord pgsString::record() const
{
	pgsRecord *rec = 0;

	// Try to find the representation of a record in the string
	{
		wxString element(wxT("(\"([^\"\\\\]|\\\\.)*\")|((-|[a-zA-Z0-9\\+\\.])+)"));
		wxString data(m_data);
		wxRegEx regex1(wxString() << wxT("^[[:space:]]*\\([[:space:]]*(")
		               << element << wxT(")[[:space:]]*([,][[:space:]]*(")
		               << element << wxT(")[[:space:]]*)*\\)"), wxRE_DEFAULT | wxRE_ICASE);

		// Find each line
		size_t line_nb = 0, nb_of_columns = 0;
		bool count_columns = true;
		while (regex1.Matches(data))
		{
			// Process that line: find each element
			wxString line(regex1.GetMatch(data));
			wxRegEx regex2(element);
			size_t column_nb = 0;
			while (regex2.Matches(line))
			{
				if (count_columns == true)
				{
					++nb_of_columns;
				}
				else
				{
					if (column_nb < nb_of_columns && rec != 0)
					{
						wxString value(regex2.GetMatch(line));
						if (value.StartsWith(wxT("\""))
						        && value.EndsWith(wxT("\"")))
						{
							// This is a string
							value = value.Mid(1, value.Len() - 2);
							value.Replace(wxT("\\\""), wxT("\""));
							value.Replace(wxT("\\\\"), wxT("\\"));
							rec->insert(line_nb, column_nb,
							            pnew pgsString(value));
						}
						else
						{
							// This is a number or a string
							pgsTypes type = pgsNumber::num_type(value);
							switch (type)
							{
								case pgsTInt:
									rec->insert(line_nb, column_nb,
									            pnew pgsNumber(value, pgsInt));
									break;
								case pgsTReal:
									rec->insert(line_nb, column_nb,
									            pnew pgsNumber(value, pgsReal));
									break;
								default:
									rec->insert(line_nb, column_nb,
									            pnew pgsString(value));
									break;
							}
						}
					}
					++column_nb;
				}

				regex2.ReplaceFirst(&line, wxT(""));
			}

			// If it is the first loop we want to process this line a
			// second time because the first one was meant to count
			// the number of columns
			if (count_columns == true)
			{
				count_columns = false;
				rec = pnew pgsRecord(nb_of_columns);
			}
			else
			{
				regex1.ReplaceFirst(&data, wxT(""));
				++line_nb;
			}
		}
	}

	// Process the case
	if (rec == 0)
	{
		rec = pnew pgsRecord(1);
		rec->insert(0, 0, this->clone());
	}

	pgsRecord ret_val(*rec);
	pdelete(rec);
	return ret_val;
}