本文整理汇总了C++中BSLS_ASSERT函数的典型用法代码示例。如果您正苦于以下问题:C++ BSLS_ASSERT函数的具体用法?C++ BSLS_ASSERT怎么用?C++ BSLS_ASSERT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BSLS_ASSERT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BSLS_ASSERT
inline
RESULT *allocate(int *status,
int flags,
const btlso::IPv4Address& peerAddress,
btlso::StreamSocketFactory<btlso::IPv4Address> *factory,
bdlma::Pool *pool)
{
BSLS_ASSERT(factory); BSLS_ASSERT(pool); BSLS_ASSERT(status);
btlso::StreamSocket<btlso::IPv4Address> *socket_p = 0;
socket_p = factory->allocate();
if (!socket_p) {
return NULL; // RETURN
}
int rc = socket_p->setBlockingMode(btlso::Flag::e_BLOCKING_MODE);
BSLS_ASSERT(0 == rc);
while (1) {
int s = socket_p->connect(peerAddress);
if (0 == s) break;
if (btlso::SocketHandle::e_ERROR_INTERRUPTED != s) {
*status = e_FAILED; // Any negative number satisfies the contract.
factory->deallocate(socket_p);
return NULL; // RETURN
}
if (flags & btlsc::Flag::k_ASYNC_INTERRUPT) {
*status = 1; // Any positive number satisfies the contract.
factory->deallocate(socket_p);
return NULL; // RETURN
}
}
RESULT *channel = new (*pool) RESULT(socket_p);
return channel;
}
示例2: BSLS_ASSERT
int baltzo::TimeZoneUtil::convertLocalToLocalTime(
LocalDatetime *result,
const char *targetTimeZoneId,
const bdlt::Datetime& srcTime,
const char *srcTimeZoneId,
DstPolicy::Enum dstPolicy)
{
BSLS_ASSERT(result);
BSLS_ASSERT(targetTimeZoneId);
BSLS_ASSERT(srcTimeZoneId);
bdlt::DatetimeTz resultTz;
const int rc = convertLocalToLocalTime(&resultTz,
targetTimeZoneId,
srcTime,
srcTimeZoneId,
dstPolicy);
if (0 != rc) {
return rc; // RETURN
}
result->setDatetimeTz(resultTz);
result->setTimeZoneId(targetTimeZoneId);
return 0;
}
示例3: BSLS_ASSERT
void RbTreeUtil::swap(RbTreeAnchor *a, RbTreeAnchor *b)
{
BSLS_ASSERT(a);
BSLS_ASSERT(b);
RbTreeAnchor tmp(a->rootNode(),
a->firstNode(),
a->numNodes());
a->reset(b->rootNode(), b->firstNode(), b->numNodes());
b->reset(tmp.rootNode(), tmp.firstNode(), tmp.numNodes());
// Readjust the sentinel nodes of both trees.
if (0 == a->numNodes()) {
a->setFirstNode(a->sentinel());
}
else {
a->rootNode()->setParent(a->sentinel());
}
if (0 == b->numNodes()) {
b->setFirstNode(b->sentinel());
}
else {
b->rootNode()->setParent(b->sentinel());
}
}
示例4: BSLS_ASSERT
void String::toFixedLength(char *dstString,
int dstLength,
const char *srcString,
int srcLength,
char padChar)
{
BSLS_ASSERT(dstString);
BSLS_ASSERT( 0 <= dstLength);
BSLS_ASSERT(srcString || 0 == srcLength);
BSLS_ASSERT( 0 <= srcLength);
if (dstLength < srcLength) {
// We know 'srcLength > 0', therefore '0 != srcString'.
if (dstString != srcString) {
bsl::memmove(dstString, srcString, dstLength);
}
}
else {
if (srcString && dstString != srcString) {
bsl::memmove(dstString, srcString, srcLength);
}
for (int i = srcLength; i < dstLength; ++i) {
dstString[i] = padChar;
}
}
}
示例5: hash
static
unsigned int hash(const char *data, int length)
// That the memory starting at the specified 'data' of specified 'length'
// bytes in length.
{
BSLS_ASSERT(0 <= length);
BSLS_ASSERT(data || 0 == length);
typedef unsigned char Ub1;
typedef unsigned int Ub4;
const Ub1 *k = reinterpret_cast<const Ub1 *>(data);
Ub4 hash = 0;
for (int i = 0; i < length; ++i) {
hash += k[i];
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return hash;
}
示例6: lock
void bslmt::Sluice::wait(const void *token)
{
GenerationDescriptor *g =
static_cast<GenerationDescriptor *>(const_cast<void *>(token));
for (;;) {
g->d_sema.wait();
LockGuard<Mutex> lock(&d_mutex);
if (g->d_numSignaled) {
const int numSignaled = --g->d_numSignaled;
const int numThreads = --g->d_numThreads;
BSLS_ASSERT(numThreads >= numSignaled);
BSLS_ASSERT(d_pendingGeneration != g);
if (0 == numThreads) {
// The last thread is responsible for cleanup.
BSLS_ASSERT(d_signaledGeneration != g);
g->d_next = d_descriptorPool;
d_descriptorPool = g;
}
return; // RETURN
}
// Spurious wakeups happen because 'timedWait' may timeout on the
// semaphore, but still consume a signal.
}
}
示例7: BSLS_ASSERT
int DecimalUtil::quantum(Decimal128 x)
{
BSLS_ASSERT(!isInf(x));
BSLS_ASSERT(!isNan(x));
return decQuadGetExponent(x.data());
}
示例8: BSLS_ASSERT
CountingAllocator::~CountingAllocator()
{
BSLS_ASSERT(0 <= numBytesInUse());
BSLS_ASSERT(0 <= numBytesTotal());
BSLS_ASSERT(numBytesInUse() <= numBytesTotal());
BSLS_ASSERT(d_allocator_p);
}
示例9: lock
int TimeMetrics::percentage(int category)
{
bslmt::LockGuard<bslmt::Mutex> lock(&d_dataLock);
int result = 0;
BSLS_ASSERT(0 <= category);
BSLS_ASSERT(category < (int) d_categoryTimes.size());
bsls::TimeInterval now = bdlt::CurrentTime::now();
bsls::TimeInterval delta = now - d_categoryStartTimes[d_currentCategory];
int deltaMS = static_cast<int>(delta.seconds() * 1000 +
delta.nanoseconds() / k_MILLION);
d_categoryTimes[d_currentCategory] += deltaMS;
d_currentTotal += deltaMS;
d_categoryStartTimes[d_currentCategory] = now;
if (d_currentTotal) {
result = static_cast<int>(
d_categoryTimes[category] * 100.0 / d_currentTotal);
}
return result < 0
? 0
: result > 100
? 100
: result;
}
示例10: BSLS_ASSERT
TimeMetrics::~TimeMetrics()
{
BSLS_ASSERT(d_categoryStartTimes.size() == d_categoryTimes.size());
BSLS_ASSERT(d_currentCategory <
static_cast<int>(d_categoryStartTimes.size()));
BSLS_ASSERT(0 <= d_currentCategory);
}
示例11: BSLS_ASSERT
// MANIPULATORS
void *BlockList::allocate(int size)
{
BSLS_ASSERT(0 <= size);
if (0 == size) {
return 0; // RETURN
}
size = alignedAllocationSize(size, sizeof(Block));
Block *block = (Block *)d_allocator_p->allocate(size);
BSLS_ASSERT(0 == bsls::AlignmentUtil::calculateAlignmentOffset(
(void *)block,
bsls::AlignmentUtil::BSLS_MAX_ALIGNMENT));
block->d_next_p = (Block *)d_head_p;
block->d_addrPrevNext = (Block **)&d_head_p;
if (d_head_p) {
d_head_p->d_addrPrevNext = &block->d_next_p;
}
d_head_p = block;
BSLS_ASSERT(0 == bsls::AlignmentUtil::calculateAlignmentOffset(
(void *)&block->d_memory,
bsls::AlignmentUtil::BSLS_MAX_ALIGNMENT));
return (void *)&block->d_memory;
}
示例12: BSLS_ASSERT
void TimeInterval::addInterval(bsls::Types::Int64 seconds,
int nanoseconds)
{
BSLS_ASSERT(isSumValidInt64(d_seconds, seconds));
BSLS_ASSERT(isSumValidInt64(
d_seconds + seconds,
(static_cast<bsls::Types::Int64>(d_nanoseconds) + nanoseconds) /
k_NANOSECS_PER_SEC));
d_seconds += seconds;
bsls::Types::Int64 nanosecs = static_cast<bsls::Types::Int64>(nanoseconds)
+ d_nanoseconds;
if (nanosecs >= k_NANOSECS_PER_SEC
|| nanosecs <= -k_NANOSECS_PER_SEC) {
d_seconds += nanosecs / k_NANOSECS_PER_SEC;
d_nanoseconds = static_cast<int>(nanosecs % k_NANOSECS_PER_SEC);
}
else {
d_nanoseconds = static_cast<int>(nanosecs);
}
if (d_seconds > 0 && d_nanoseconds < 0) {
--d_seconds;
d_nanoseconds += k_NANOSECS_PER_SEC;
}
else if (d_seconds < 0 && d_nanoseconds > 0) {
++d_seconds;
d_nanoseconds -= k_NANOSECS_PER_SEC;
}
}
示例13: BSLS_ASSERT
void TcpConnector::deallocate(btlsc::Channel *channel)
{
BSLS_ASSERT(channel);
char *arena = (char *) channel;
TcpTimedChannel *c =
dynamic_cast<TcpTimedChannel*>(channel);
btlso::StreamSocket<btlso::IPv4Address> *s = NULL;
if (c) {
s = c->socket();
}
else {
TcpChannel *c =
dynamic_cast<TcpChannel*>(channel);
BSLS_ASSERT(c);
s = c->socket();
}
BSLS_ASSERT(s);
channel->invalidate();
d_factory_p->deallocate(s);
bsl::vector<btlsc::Channel*>::iterator idx =
bsl::lower_bound(d_channels.begin(), d_channels.end(), channel);
BSLS_ASSERT(idx != d_channels.end() && *idx == channel);
d_channels.erase(idx);
d_pool.deallocate(arena);
return ;
}
示例14: BSLS_ASSERT
int btlso::SocketImpUtil::write(const btlso::SocketHandle::Handle& socket,
const void *buffer,
int numBytes,
int *errorCode)
{
// Implementation notes: For non blocking IO, the send operation will write
// out some or all of the buffer if possible. However, since the
// implementation of sockets may include internal buffers of certain sizes
// and optimizations, the send function may return a "would block" error or
// an smaller than expected number of bytes written even if it appears as
// if the internal socket buffer has more room. This is known as the low
// water mark and may be implemented even if the equivalent socket option
// is not available. For the blocking IO case, the send operation may
// block until all or part of the data is written. No assumption should be
// made regarding the number of bytes that will be written with a single
// call.
int rc;
BSLS_ASSERT(buffer);
BSLS_ASSERT(numBytes >= 0);
rc = ::send(socket, static_cast<const char *>(buffer), numBytes, 0);
int errorNumber = rc >= 0 ? 0 : SocketImpUtil_Util::getErrorCode();
if (errorNumber && errorCode) {
*errorCode = errorNumber;
}
return errorNumber ? SocketImpUtil_Util::mapErrorCode(errorNumber) : rc;
}
示例15: d_mutex
// CREATORS
ChannelPoolChannel::ChannelPoolChannel(
int channelId,
ChannelPool *channelPool,
btlb::BlobBufferFactory *blobBufferFactory,
bdlma::ConcurrentPoolAllocator *spAllocator,
bslma::Allocator *basicAllocator)
: d_mutex()
, d_callbackInProgress(false)
, d_closed(false)
, d_readQueue(basicAllocator)
, d_blobBufferFactory_p(blobBufferFactory,
0,
&bslma::ManagedPtrUtil::noOpDeleter)
, d_spAllocator_p(spAllocator)
, d_channelPool_p(channelPool)
, d_nextClockId(channelId + 0x00800000)
, d_channelId(channelId)
, d_peerAddress()
, d_localAddress()
, d_allocator_p(bslma::Default::allocator(basicAllocator))
{
BSLS_ASSERT(0 != channelPool);
BSLS_ASSERT(0 != blobBufferFactory);
BSLS_ASSERT(0 != spAllocator);
// Queue these addresses since the ChannelPool channel can have
// disappeared when we get SESSION_DOWN.
d_channelPool_p->getLocalAddress(&d_localAddress, d_channelId);
d_channelPool_p->getPeerAddress(&d_peerAddress, d_channelId);
}