当前位置: 首页>>代码示例>>C++>>正文


C++ boost::scoped_array类代码示例

本文整理汇总了C++中boost::scoped_array的典型用法代码示例。如果您正苦于以下问题:C++ scoped_array类的具体用法?C++ scoped_array怎么用?C++ scoped_array使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了scoped_array类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setupInput

/** Sets up the spline object by with the parameters and attributes
 *
 * @param x :: The array of x values defining the spline
 * @param y :: The array of y values defining the spline
 * @param n :: The size of the arrays
 */
void CubicSpline::setupInput(boost::scoped_array<double> &x,
                             boost::scoped_array<double> &y, int n) const {
  // Populate data points from the input attributes and parameters
  bool xSortFlag = false;

  for (int i = 0; i < n; ++i) {
    std::string num = boost::lexical_cast<std::string>(i);

    std::string xName = "x" + num;
    std::string yName = "y" + num;

    x[i] = getAttribute(xName).asDouble();

    // if x[i] is out of order with its neighbours
    if (i > 1 && i < n && (x[i - 1] < x[i - 2] || x[i - 1] > x[i])) {
      xSortFlag = true;
    }

    y[i] = getParameter(yName);
  }

  // sort the data points if necessary
  if (xSortFlag) {
    g_log.warning() << "Spline x parameters are not in ascending order. Values "
                       "will be sorted." << std::endl;
    std::sort(x.get(), x.get() + n);
  }

  // pass values to GSL objects
  initGSLObjects(x, y, n);
  m_recalculateSpline = false;
}
开发者ID:mkoennecke,项目名称:mantid,代码行数:38,代码来源:CubicSpline.cpp

示例2: LOG

    void FileAllocator::ensureLength(int fd , long size) {
#if !defined(_WIN32)
        if (useSparseFiles(fd)) {
            LOG(1) << "using ftruncate to create a sparse file" << endl;
            int ret = ftruncate(fd, size);
            uassert(16063, "ftruncate failed: " + errnoWithDescription(), ret == 0);
            return;
        }
#endif

#if defined(__linux__)
        int ret = posix_fallocate(fd,0,size);
        if ( ret == 0 )
            return;

        log() << "FileAllocator: posix_fallocate failed: " << errnoWithDescription( ret ) << " falling back" << endl;
#endif

        off_t filelen = lseek( fd, 0, SEEK_END );
        if ( filelen < size ) {
            if (filelen != 0) {
                stringstream ss;
                ss << "failure creating new datafile; lseek failed for fd " << fd << " with errno: " << errnoWithDescription();
                uassert( 10440 ,  ss.str(), filelen == 0 );
            }
            // Check for end of disk.

            uassert( 10441 ,  str::stream() << "Unable to allocate new file of size " << size << ' ' << errnoWithDescription(),
                     size - 1 == lseek(fd, size - 1, SEEK_SET) );
            uassert( 10442 ,  str::stream() << "Unable to allocate new file of size " << size << ' ' << errnoWithDescription(),
                     1 == write(fd, "", 1) );

            // File expansion is completed here. Do not do the zeroing out on OS-es where there
            // is no risk of triggering allocation-related bugs such as
            // http://support.microsoft.com/kb/2731284.
            //
            if (!ProcessInfo::isDataFileZeroingNeeded()) {
                return;
            }

            lseek(fd, 0, SEEK_SET);

            const long z = 256 * 1024;
            const boost::scoped_array<char> buf_holder (new char[z]);
            char* buf = buf_holder.get();
            memset(buf, 0, z);
            long left = size;
            while ( left > 0 ) {
                long towrite = left;
                if ( towrite > z )
                    towrite = z;

                int written = write( fd , buf , towrite );
                uassert( 10443 , errnoWithPrefix("FileAllocator: file write failed" ), written > 0 );
                left -= written;
            }
        }
    }
开发者ID:DeathBorn,项目名称:mongo,代码行数:58,代码来源:file_allocator.cpp

示例3: LOG

    void FileAllocator::ensureLength(int fd , long size) {
#if !defined(_WIN32)
        if (useSparseFiles(fd)) {
            LOG(1) << "using ftruncate to create a sparse file" << endl;
            int ret = ftruncate(fd, size);
            uassert(16063, "ftruncate failed: " + errnoWithDescription(), ret == 0);
            return;
        }
#endif

#if defined(__linux__)
        int ret = posix_fallocate(fd,0,size);
        if ( ret == 0 )
            return;

        log() << "FileAllocator: posix_fallocate failed: " << errnoWithDescription( ret ) << " falling back" << endl;
#endif

        off_t filelen = lseek( fd, 0, SEEK_END );
        if ( filelen < size ) {
            if (filelen != 0) {
                stringstream ss;
                ss << "failure creating new datafile; lseek failed for fd " << fd << " with errno: " << errnoWithDescription();
                uassert( 10440 ,  ss.str(), filelen == 0 );
            }
            // Check for end of disk.

            uassert( 10441 ,  str::stream() << "Unable to allocate new file of size " << size << ' ' << errnoWithDescription(),
                     size - 1 == lseek(fd, size - 1, SEEK_SET) );
            uassert( 10442 ,  str::stream() << "Unable to allocate new file of size " << size << ' ' << errnoWithDescription(),
                     1 == write(fd, "", 1) );
            lseek(fd, 0, SEEK_SET);

            const long z = 256 * 1024;
            const boost::scoped_array<char> buf_holder (new char[z]);
            char* buf = buf_holder.get();
            memset(buf, 0, z);
            long left = size;
            while ( left > 0 ) {
                long towrite = left;
                if ( towrite > z )
                    towrite = z;

                int written = write( fd , buf , towrite );
                uassert( 10443 , errnoWithPrefix("FileAllocator: file write failed" ), written > 0 );
                left -= written;
            }
        }
    }
开发者ID:328500920,项目名称:mongo,代码行数:49,代码来源:file_allocator.cpp

示例4: _InitBCrypt

HRESULT CKeyTransformBCrypt::_InitBCrypt(BCRYPT_ALG_HANDLE& hAes, BCRYPT_KEY_HANDLE& hKey,
	boost::scoped_array<UCHAR>& pKeyObj, const BYTE* pbKey32)
{
	if(m_lpBCryptOpenAlgorithmProvider(&hAes, BCRYPT_AES_ALGORITHM, NULL, 0) != 0)
	{
		ASSERT(FALSE);
		return E_FAIL;
	}

	DWORD dwKeyObjLen = 0;
	ULONG uResult = 0;
	if(m_lpBCryptGetProperty(hAes, BCRYPT_OBJECT_LENGTH, (PUCHAR)&dwKeyObjLen,
		sizeof(DWORD), &uResult, 0) != 0) KTBC_FAIL;
	if(dwKeyObjLen == 0) KTBC_FAIL;

	pKeyObj.reset(new UCHAR[dwKeyObjLen]);

	if(m_lpBCryptSetProperty(hAes, BCRYPT_CHAINING_MODE, (PUCHAR)BCRYPT_CHAIN_MODE_ECB,
		static_cast<ULONG>((wcslen(BCRYPT_CHAIN_MODE_ECB) + 1) * sizeof(wchar_t)), 0) != 0)
		KTBC_FAIL;

	BCRYPT_KEY_DATA_BLOB_32 keyBlob;
	ZeroMemory(&keyBlob, sizeof(BCRYPT_KEY_DATA_BLOB_32));
	keyBlob.dwMagic = BCRYPT_KEY_DATA_BLOB_MAGIC;
	keyBlob.dwVersion = BCRYPT_KEY_DATA_BLOB_VERSION1;
	keyBlob.cbKeyData = 32;
	memcpy(keyBlob.pbData, pbKey32, 32);

	// if(m_lpBCryptGenerateSymmetricKey(hAes, &hKey, (PUCHAR)pKeyObj.get(),
	//	dwKeyObjLen, const_cast<PUCHAR>(pbKey32), 32, 0) != 0) KTBC_FAIL;
	if(m_lpBCryptImportKey(hAes, NULL, BCRYPT_KEY_DATA_BLOB, &hKey,
		pKeyObj.get(), dwKeyObjLen, (PUCHAR)&keyBlob,
		sizeof(BCRYPT_KEY_DATA_BLOB_32), 0) != 0) KTBC_FAIL;

#ifdef _DEBUG
	DWORD dwKeyLen = 0;
	VERIFY(m_lpBCryptGetProperty(hKey, BCRYPT_KEY_STRENGTH, (PUCHAR)&dwKeyLen,
		sizeof(DWORD), &uResult, 0) == 0);
	VERIFY(dwKeyLen == 256);

	BCRYPT_ALG_HANDLE hRef = NULL;
	VERIFY(m_lpBCryptGetProperty(hKey, BCRYPT_PROVIDER_HANDLE, (PUCHAR)&hRef,
		sizeof(BCRYPT_ALG_HANDLE), &uResult, 0) == 0);
	VERIFY(hRef == hAes);
#endif

	return S_OK;
}
开发者ID:xt9852,项目名称:KeePassXT,代码行数:48,代码来源:KeyTransform_BCrypt.cpp

示例5: init_old_buffer

	void init_old_buffer(boost::scoped_array<unsigned long long> &array, const std::size_t size) {
		if (!array) {
			array.reset(new unsigned long long[size]);
			for (std::size_t i=0;i<size;i++) {
				array[i] = 0;
			}
		}
	}
开发者ID:TaylorMonacelli,项目名称:nscp,代码行数:8,代码来源:win_sysinfo.cpp

示例6: TaskId

 TaskId(std::string const & workTitle, uint32_t id,
        boost::scoped_array<uint8_t> const & taskData,
        size_t taskDataSize) :
     m_workId(workTitle, id),
     m_taskData(new uint8_t[taskDataSize]),
     m_taskDataSize(taskDataSize)
 {
     memcpy(m_taskData.get(), taskData.get(), taskDataSize);
 }
开发者ID:edwardt,项目名称:CloudI,代码行数:9,代码来源:task_id.hpp

示例7: splitAudioData

void AudioResampleImpl::splitAudioData(AudioData & data, boost::scoped_array<char*> & split) const
{
	auto dataFormat = data.format();

	if (dataFormat.isPlanar())
	{
		/// Для планарного формата необходимо представить данные из result
		const int numChannels = dataFormat.channelCount();
		split.reset(new char*[numChannels]);
		split_ref(data.begin(), data.end(), data.numBytes() / numChannels, split.get());
	}
	else
	{
		/// Interleaved данные помещаются в один массив
		split.reset(new char*[1]);
		split[0] = data.data();
	}
}
开发者ID:wagut,项目名称:play,代码行数:18,代码来源:AudioResampleImpl.cpp

示例8: Close

void LightProcess::Close() {
  boost::scoped_array<LightProcess> procs;
  procs.swap(g_procs);
  int count = g_procsCount;
  g_procs.reset();
  g_procsCount = 0;

  for (int i = 0; i < count; i++) {
    procs[i].closeShadow();
  }
}
开发者ID:Alienfeel,项目名称:hhvm,代码行数:11,代码来源:light-process.cpp

示例9: deprecation

//-----------------------------------------------------------------------------
void dolfin::deprecation(std::string feature,
                         std::string version,
                         std::string message, ...)
{
  read(buffer.get(), message);
  LogManager::logger.deprecation(feature, version, buffer.get());
}
开发者ID:alogg,项目名称:dolfin,代码行数:8,代码来源:log.cpp

示例10: dolfin_error

//-----------------------------------------------------------------------------
void dolfin::dolfin_error(std::string location,
                          std::string task,
                          std::string reason, ...)
{
  read(buffer.get(), reason);
  LogManager::logger.dolfin_error(location, task, buffer.get());
}
开发者ID:alogg,项目名称:dolfin,代码行数:8,代码来源:log.cpp

示例11: info

//-----------------------------------------------------------------------------
void dolfin::info(std::string msg, ...)
{
  if (!LogManager::logger.is_active())
    return; // optimization
  read(buffer.get(), msg);
  LogManager::logger.log(buffer.get());
}
开发者ID:alogg,项目名称:dolfin,代码行数:8,代码来源:log.cpp

示例12: __debug

//-----------------------------------------------------------------------------
void dolfin::__debug(std::string file, unsigned long line,
                     std::string function, std::string format, ...)
{
  read(buffer.get(), format);
  std::ostringstream ost;
  ost << file << ":" << line << " in " << function << "()";
  std::string msg = std::string(buffer.get()) + " [at " + ost.str() + "]";
  LogManager::logger.__debug(msg);
}
开发者ID:alogg,项目名称:dolfin,代码行数:10,代码来源:log.cpp

示例13: Initialize

void LightProcess::Initialize(const std::string &prefix, int count,
                              const std::vector<int> &inherited_fds) {
  if (prefix.empty() || count <= 0) {
    return;
  }

  if (Available()) {
    // already initialized
    return;
  }

  g_procs.reset(new LightProcess[count]);
  g_procsCount = count;

  auto afdt_filename = folly::sformat("{}.{}", prefix, getpid());

  // remove the possible leftover
  remove(afdt_filename.c_str());

  afdt_error_t err = AFDT_ERROR_T_INIT;
  auto afdt_lid = afdt_listen(afdt_filename.c_str(), &err);
  if (afdt_lid < 0) {
    Logger::Warning("Unable to afdt_listen to %s: %d %s",
                    afdt_filename.c_str(),
                    errno, folly::errnoStr(errno).c_str());
    return;
  }

  SCOPE_EXIT {
    ::close(afdt_lid);
    remove(afdt_filename.c_str());
  };

  for (int i = 0; i < count; i++) {
    if (!g_procs[i].initShadow(afdt_lid, afdt_filename, i, inherited_fds)) {
      for (int j = 0; j < i; j++) {
        g_procs[j].closeShadow();
      }
      g_procs.reset();
      g_procsCount = 0;
      break;
    }
  }

  if (!s_handlerInited) {
    struct sigaction sa;
    struct sigaction old_sa;
    sa.sa_sigaction = &LightProcess::SigChldHandler;
    sa.sa_flags = SA_SIGINFO | SA_NOCLDSTOP;
    if (sigaction(SIGCHLD, &sa, &old_sa) != 0) {
      Logger::Error("Couldn't install SIGCHLD handler");
      abort();
    }
    s_handlerInited = true;
  }
}
开发者ID:craigcarnell,项目名称:hhvm,代码行数:56,代码来源:light-process.cpp

示例14: Close

void LightProcess::Close() {
  for (int i = 0; i < g_procsCount; i++) {
    g_procs[i].closeShadow();
  }
  g_procs.reset();
  g_procsCount = 0;
}
开发者ID:HyeongKyu,项目名称:hiphop-php,代码行数:7,代码来源:light_process.cpp

示例15: if

inline LogCodec::int_type LogCodec::consumeVoidsAndComments(streambuf_type *buf_ptr)
{
	int_type c = buf_ptr->sgetc();
	char * const read_buf = m_read_buf.get();
	char * read_ptr;

	while (!traits_type::eq_int_type(c, traits_type::eof())) {
		if (m_field_split.find(c) != std::string::npos || m_event_split.find(c) != std::string::npos) {
			c = buf_ptr->snextc();
		} else if (m_comment_chars.find(c) != std::string::npos) {
			// ignore comment line (sorta...)
			read_ptr = read_buf;
			do {
				// check for end of line
				if (m_event_split.find(c) != std::string::npos)
					break;
				// read in the comment in case it matters...
				if (read_ptr < m_read_end)
					*(read_ptr++) = c;
				// get the next character
				c = buf_ptr->snextc();
			} while (!traits_type::eq_int_type(c, traits_type::eof()));
			*read_ptr = '\0';
			if (m_handle_elf_headers) {
				// check if it is an ELF format change
				read_buf[FIELDS_ELF_HEADER.size()] = '\0';
				if (FIELDS_ELF_HEADER == read_buf)
					changeELFFormat(read_buf + FIELDS_ELF_HEADER.size() + 1);
			}
		} else {
			break;
		}
	}
	return c;
}
开发者ID:acmorrow,项目名称:pion-core,代码行数:35,代码来源:LogCodec.hpp


注:本文中的boost::scoped_array类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。