本文整理汇总了C++中Ctxt函数的典型用法代码示例。如果您正苦于以下问题:C++ Ctxt函数的具体用法?C++ Ctxt怎么用?C++ Ctxt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Ctxt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
void sys::File::readInto(char *buffer, Size_T size)
{
static const size_t MAX_READ_SIZE = std::numeric_limits<DWORD>::max();
size_t bytesRead = 0;
size_t bytesRemaining = size;
while (bytesRead < size)
{
// Determine how many bytes to read
const DWORD bytesToRead = static_cast<DWORD>(
std::min(MAX_READ_SIZE, bytesRemaining));
// Read from file
DWORD bytesThisRead = 0;
if (!ReadFile(mHandle,
buffer + bytesRead,
bytesToRead,
&bytesThisRead,
NULL))
{
throw sys::SystemException(Ctxt("Error reading from file"));
}
else if (bytesThisRead == 0)
{
//! ReadFile does not fail when finding the EOF --
// instead it reports 0 bytes read, so this stops an infinite loop
// from Unexpected EOF
throw sys::SystemException(Ctxt("Unexpected end of file"));
}
bytesRead += bytesThisRead;
bytesRemaining -= bytesThisRead;
}
}
示例2: while
double Utilities::remapZeroTo360(double degree)
{
double delta = degree;
while (delta < 0.)
{
delta += 360.;
if (degree == delta)
{
throw except::Exception(Ctxt(
"Value [" + str::toString(degree) +
"] is too small to remap into the [0:360] range"));
}
}
while (delta > 360.)
{
delta -= 360.;
if (degree == delta)
{
throw except::Exception(Ctxt(
"Value [" + str::toString(degree) +
"] is too large to remap into the [0:360] range"));
}
}
return delta;
}
示例3: catch
void mt::ThreadGroup::joinAll()
{
bool failed = false;
// Keep track of which threads we've already joined.
for (; mLastJoined < mThreads.size(); mLastJoined++)
{
try
{
mThreads[mLastJoined]->join();
}
catch (...)
{
failed = true;
}
}
if (!mExceptions.empty())
{
std::string messageString("Exceptions thrown from ThreadGroup in the following order:\n");
for (size_t ii=0; ii<mExceptions.size(); ++ii)
{
messageString += mExceptions.at(ii).toString();
}
throw except::Exception(Ctxt(messageString));
}
if (failed)
throw except::Error(Ctxt("ThreadGroup could not be joined"));
}
示例4: Exception
const ScratchMemory::Segment& ScratchMemory::lookupSegment(
const std::string& key,
size_t indexBuffer) const
{
if (mBuffer.data == NULL)
{
std::ostringstream oss;
oss << "Tried to get scratch memory for \"" << key
<< "\" before running setup.";
throw except::Exception(Ctxt(oss.str()));
}
std::map<std::string, Segment>::const_iterator iterSeg = mSegments.find(key);
if (iterSeg == mSegments.end())
{
std::ostringstream oss;
oss << "Scratch memory segment was not found for \"" << key << "\"";
throw except::Exception(Ctxt(oss.str()));
}
const Segment& segment = iterSeg->second;
if (indexBuffer >= segment.buffers.size())
{
std::ostringstream oss;
oss << "Trying to get buffer index " << indexBuffer << " for \""
<< key << "\", which has only " << segment.buffers.size()
<< " buffers";
throw except::Exception(Ctxt(oss.str()));
}
return segment;
}
示例5: getSideOfTrack
std::auto_ptr<scene::ProjectionModel>
Utilities::getProjectionModel(const DerivedData* data)
{
const int lookDir = getSideOfTrack(data);
scene::Errors errors;
::getErrors(*data, errors);
std::auto_ptr<scene::SceneGeometry> geom(getSceneGeometry(data));
const six::ProjectionType gridType =
data->measurement->projection->projectionType;
std::auto_ptr<scene::ProjectionModel> projModel;
switch (gridType)
{
case six::ProjectionType::PLANE:
{
const six::sidd::PlaneProjection* const plane =
reinterpret_cast<six::sidd::PlaneProjection*>(
data->measurement->projection.get());
projModel.reset(new scene::PlaneProjectionModel(
geom->getSlantPlaneZ(),
plane->productPlane.rowUnitVector,
plane->productPlane.colUnitVector,
plane->referencePoint.ecef,
data->measurement->arpPoly,
plane->timeCOAPoly,
lookDir,
errors));
break;
}
case six::ProjectionType::GEOGRAPHIC:
{
const six::sidd::MeasurableProjection* const geo =
reinterpret_cast<six::sidd::MeasurableProjection*>(
data->measurement->projection.get());
projModel.reset(new scene::GeodeticProjectionModel(
geom->getSlantPlaneZ(),
geo->referencePoint.ecef,
data->measurement->arpPoly,
geo->timeCOAPoly,
lookDir,
errors));
break;
}
case six::ProjectionType::POLYNOMIAL:
case six::ProjectionType::CYLINDRICAL:
case six::ProjectionType::NOT_SET:
throw except::Exception(Ctxt("Grid type not supported: " +
gridType.toString()));
default:
throw except::Exception(Ctxt("Invalid grid type: " +
gridType.toString()));
}
return projModel;
}
示例6: throw
nitf::Pair nitf::HashTable::find(const std::string& key) throw(except::NoSuchKeyException)
{
if (key.length() == 0)
throw except::NoSuchKeyException(Ctxt("Empty key value"));
nitf_Pair* x = nitf_HashTable_find(getNative(), key.c_str());
if (!x)
throw except::NoSuchKeyException(Ctxt(key));
return nitf::Pair(x);
}
示例7: defined
void net::ssl::SSLConnectionClientFactory::initializeContext()
{
#if defined(USE_OPENSSL)
SSL_library_init();
SSL_load_error_strings();
#if defined(OPENSSL_0_9_8)
SSL_METHOD *method = SSLv23_client_method();
#else
const SSL_METHOD *method = SSLv23_client_method();
#endif
if(method == NULL)
{
throw net::ssl::SSLException(Ctxt(FmtX("SSLv23_client_method failed")));
}
mCtx = SSL_CTX_new(method);
if(mCtx == NULL)
{
throw net::ssl::SSLException(Ctxt(FmtX("SSL_CTX_new failed")));
}
if(mClientAuthentication)
{
// Load our keys and certificates
if(!(SSL_CTX_use_certificate_file(mCtx, mKeyfile.c_str(), SSL_FILETYPE_PEM)))
throw net::ssl::SSLException(Ctxt("Can't read certificate file"));
//SSL_CTX_set_default_passwd_cb(mCtx, password_cb);
if(!(SSL_CTX_use_PrivateKey_file(mCtx, mKeyfile.c_str(), SSL_FILETYPE_PEM)))
throw net::ssl::SSLException(Ctxt("Can't read key file"));
// Load the CAs we trust
if(!(SSL_CTX_load_verify_locations(mCtx, mCAList.c_str(), 0)))
throw net::ssl::SSLException(Ctxt("Can't read CA list"));
// Set our cipher list
if(mCiphers)
{
SSL_CTX_set_cipher_list(mCtx, mCiphers);
}
}
// Load randomness
/*
if(!RAND_load_file("random.pem", 1024*1024))
throw net::ssl::SSLException(Ctxt("Couldn't load randomness"));
*/
#if (OPENSSL_VERSION_NUMBER < 0x00905100L)
SSL_CTX_set_verify_depth(mCtx, 1);
#endif
#endif
}
示例8: buf
void FileHeader::blockReadHeader(io::SeekableInputStream& inStream,
size_t blockSize,
std::string& headerBlock)
{
static const char ERROR_MSG[] = "CPHD file malformed: Header must terminate with '\\f\\n'";
mem::ScopedArray<sys::byte> buf(new sys::byte[blockSize + 1]);
std::fill_n(buf.get(), blockSize + 1, 0);
headerBlock.clear();
// read each block in succession
size_t terminatorLoc = std::string::npos;
size_t totalBytesRead = 0;
while (inStream.read(buf.get(), blockSize) != io::InputStream::IS_EOF &&
terminatorLoc == std::string::npos)
{
std::string thisBlock = buf.get();
// find the terminator in the block
terminatorLoc = thisBlock.find('\f');
if (terminatorLoc != std::string::npos)
{
// read one more byte if our block missed the trailing '\n'
if (terminatorLoc == thisBlock.length() - 1)
{
sys::byte c(0);
inStream.read(&c, 1);
thisBlock.insert(thisBlock.length(), &c, 1);
}
// verify proper formatting
if (thisBlock[terminatorLoc + 1] != '\n')
{
throw except::Exception(Ctxt(ERROR_MSG));
}
// trim off anything after the terminator
thisBlock = thisBlock.substr(0, terminatorLoc);
}
// build the header
headerBlock += thisBlock;
// verify we aren't past 10MB in the header --
// this stops processing before we start reading into the
// image data and potentially run out of memory
totalBytesRead += thisBlock.length();
if (totalBytesRead > MAX_HEADER_SIZE)
{
throw except::Exception(Ctxt(ERROR_MSG));
}
}
}
示例9: findSegment
void ImageBlocker::findSegmentRange(size_t startRow,
size_t numRows,
size_t& firstSegIdx,
size_t& startBlockWithinFirstSeg,
size_t& lastSegIdx,
size_t& lastBlockWithinLastSeg) const
{
if (numRows == 0)
{
firstSegIdx = startBlockWithinFirstSeg =
lastSegIdx = lastBlockWithinLastSeg =
std::numeric_limits<size_t>::max();
}
else
{
// Figure out which segment we're starting in
size_t startRowWithinFirstSeg;
findSegment(startRow, firstSegIdx, startRowWithinFirstSeg,
startBlockWithinFirstSeg);
if (!isFirstRowInBlock(startRowWithinFirstSeg))
{
std::ostringstream ostr;
ostr << "Start row " << startRow << " is local row "
<< startRowWithinFirstSeg << " within segment " << firstSegIdx
<< ". The local row must be a multiple of "
<< mNumRowsPerBlock << ".";
throw except::Exception(Ctxt(ostr.str()));
}
// Figure out which segment we're ending in
const size_t lastRow = startRow + numRows - 1;
size_t lastRowWithinLastSeg;
findSegment(lastRow, lastSegIdx, lastRowWithinLastSeg,
lastBlockWithinLastSeg);
const size_t endRowWithinLastSeg = lastRowWithinLastSeg + 1;
// Make sure we're ending on a full block
if (!(endRowWithinLastSeg == mNumRows[lastSegIdx] ||
isFirstRowInBlock(endRowWithinLastSeg)))
{
std::ostringstream ostr;
ostr << "Last row " << lastRow << " is local row "
<< lastRowWithinLastSeg << " within segment " << lastSegIdx
<< ". This must land on a full block.";
throw except::Exception(Ctxt(ostr.str()));
}
}
}
示例10: Ctxt
int sys::ExecPipe::closePipe()
{
if (!mOutStream)
{
throw except::IOException(
Ctxt("The stream is already closed"));
}
// in case it fails
FILE* tmp = mOutStream;
mOutStream = NULL;
int exitStatus = 0;
const int encodedStatus = pclose(tmp);
if (WIFEXITED(encodedStatus))
{
// get exit code from child process
exitStatus = WEXITSTATUS(encodedStatus);
}
else
{
//! unix gives a little better granularity on errors
// due to uncaught signal (ex. segFault)
if (WIFSIGNALED(encodedStatus))
{
throw except::IOException(
Ctxt("The child process was terminated by " \
"an uncaught signal: " +
str::toString<int>(WTERMSIG(encodedStatus))));
}
// due to unplanned stoppage
if (WIFSTOPPED(encodedStatus))
{
throw except::IOException(
Ctxt("The child process was unexpectedly stopped: " +
str::toString<int>(WSTOPSIG(encodedStatus))));
}
// all other errors
sys::SocketErr err;
throw except::IOException(
Ctxt("Failure while closing stream to child process: " +
err.toString()));
}
return exitStatus;
}
示例11: defined
std::string sys::OSUnix::getTempName(const std::string& path,
const std::string& prefix) const
{
std::string name;
#if defined(_USE_MKSTEMP) || defined(__linux__) || defined(__linux) || defined(linux__)
std::string pathname(path);
pathname += "/" + prefix + "XXXXXX";
std::vector<char> fullPath(pathname.size() + 1);
strcpy(&fullPath[0], pathname.c_str());
int ret = mkstemp(&fullPath[0]);
if (ret == -1) name = "";
else
{
name = &fullPath[0];
}
#else
CharWrapper tempname = tempnam(path.c_str(), prefix.c_str());
if (tempname.get() == NULL)
name = "";
else
{
name = tempname.get();
sys::File (name, sys::File::WRITE_ONLY, sys::File::CREATE);
}
#endif
if (name.empty())
{
throw except::Exception(Ctxt("Unable to create a temporary file"));
}
return name;
}
示例12: packedRecrypt
// Use packed bootstrapping, so we can bootstrap all in just one go.
void packedRecrypt(const CtPtrs& cPtrs,
const std::vector<zzX>& unpackConsts,
const EncryptedArray& ea)
{
FHEPubKey& pKey = (FHEPubKey&)cPtrs[0]->getPubKey();
// Allocate temporary ciphertexts for the recryption
int nPacked = divc(cPtrs.size(), ea.getDegree()); // ceil(totoalNum/d)
std::vector<Ctxt> cts(nPacked, Ctxt(pKey));
repack(CtPtrs_vectorCt(cts), cPtrs, ea); // pack ciphertexts
// cout << "@"<< lsize(cts)<<std::flush;
for (Ctxt& c: cts) { // then recrypt them
c.reducePtxtSpace(2); // we only have recryption data for binary ctxt
#ifdef DEBUG_PRINTOUT
ZZX ptxt;
decryptAndPrint((cout<<" before recryption "), c, *dbgKey, *dbgEa);
dbgKey->Decrypt(ptxt, c);
c.DummyEncrypt(ptxt);
decryptAndPrint((cout<<" after recryption "), c, *dbgKey, *dbgEa);
#else
pKey.reCrypt(c);
#endif
}
unpack(cPtrs, CtPtrs_vectorCt(cts), ea, unpackConsts);
}
示例13: destroy
Regex& Regex::compile(const std::string& pattern)
{
mPattern = pattern;
destroy();
// TODO: So, I would like an RAII object for this. But, this object would
// need to call pcre2_compile() in its constructor rather than take
// ownership of a pointer (so that it has access to the error code
// information on failure) and its copy constructor / assignment
// operator would need to hold onto mPattern. At that point the
// class is close to being this Regex class itself.
static const int FLAGS = PCRE2_DOTALL;
int errorCode;
PCRE2_SIZE errorOffset;
mPCRE = pcre2_compile(reinterpret_cast<PCRE2_SPTR>(mPattern.c_str()),
mPattern.length(),
FLAGS,
&errorCode,
&errorOffset,
NULL); // Use default compile context
if (mPCRE == NULL)
{
std::ostringstream ostr;
ostr << "PCRE compilation failed at offset " << errorOffset
<< ": " << getErrorMessage(errorCode);
throw RegexException(Ctxt(ostr.str()));
}
return *this;
}
示例14: addImage
void CPHDWriter::addImage(const T* image,
const types::RowCol<size_t>& dims,
const sys::ubyte* vbmData)
{
if (mElementSize != sizeof(T))
{
throw except::Exception(Ctxt(
"Incorrect buffer data type used for metadata!"));
}
//! If this is the first time you called addImage. We will clear
// out the metadata image here and start adding it manually.
if (mCPHDData.empty())
{
mMetadata.data.arraySize.clear();
mMetadata.data.numCPHDChannels = 0;
}
mVBMData.push_back(vbmData);
mCPHDData.push_back(reinterpret_cast<const sys::ubyte*>(image));
mCPHDSize += dims.normL1() * mElementSize;
mVBMSize += dims.row * mMetadata.data.getNumBytesVBP();
mMetadata.data.numCPHDChannels += 1;
mMetadata.data.arraySize.push_back(ArraySize(dims.row, dims.col));
}
示例15: throw
void ImageSubheader::setPixelInformation(std::string pvtype,
nitf::Uint32 nbpp,
nitf::Uint32 abpp,
std::string justification,
std::string irep, std::string icat,
std::vector<nitf::BandInfo>& bands) throw(nitf::NITFException)
{
const size_t bandCount = bands.size();
nitf_BandInfo ** bandInfo = (nitf_BandInfo **)NITF_MALLOC(
sizeof(nitf_BandInfo*) * bandCount);
if (!bandInfo)
{
throw nitf::NITFException(Ctxt(FmtX("Out of Memory")));
}
for (size_t i = 0; i < bandCount; i++)
{
bandInfo[i] = nitf_BandInfo_clone(bands[i].getNative(), &error);
if (!bandInfo[i])
throw nitf::NITFException(&error);
}
NITF_BOOL x = nitf_ImageSubheader_setPixelInformation(getNativeOrThrow(),
pvtype.c_str(), nbpp, abpp, justification.c_str(), irep.c_str(),
icat.c_str(), static_cast<nitf::Uint32>(bandCount), bandInfo, &error);
if (!x)
throw nitf::NITFException(&error);
}