• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ UtlHashBag类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: and

// Get all bindings expiring before newerThanTime.
void
RegistrationDB::getAllOldBindings(int newerThanTime,
                                  UtlHashBag& rAors) const
{
   // Empty the return value.
   rAors.destroyAll();

   if ( m_pFastDB != NULL )
   {
      SMART_DB_ACCESS;

      // Note: callid set to null indicates provisioned entries and
      //        these should not be removed
      dbQuery query;
      query = "expires <", static_cast<const int&>(newerThanTime), " and (callid != '#')";
      dbCursor< RegistrationRow > cursor;
      int rows = cursor.select( query );
      if (rows > 0)
      {
         // Create UtlString containing the AOR from the "uri" column.
         UtlString* uri = new UtlString(cursor->uri);
         // Add it to the result set.
         rAors.insert(uri);
      } while ( cursor.next() );
   }
   else
   {
      OsSysLog::add(FAC_DB, PRI_CRIT, "RegistrationDB::getAllOldBindings failed - no DB");
   }

   return;
}
开发者ID:mranga,项目名称:sipxecs,代码行数:33,代码来源:RegistrationDB.cpp


示例2: removeKey

    /*!a test case for the interaction of remove() and key().
    */
    void removeKey()
    {
       UtlString v1("a");
       UtlString v2("b");
       UtlString v3("c");
       UtlString v4("d");
       UtlContainable* e;

       UtlHashBag h;
       h.insert(&v1);
       h.insert(&v2);
       h.insert(&v3);
       h.insert(&v4);

       UtlHashBagIterator iter(h);

       // Check that key() returns NULL in the initial state.
       CPPUNIT_ASSERT(iter.key() == NULL);

       // Step the iterator and check that key() returns non-NULL.
       e = iter();
       CPPUNIT_ASSERT(e != NULL);
       CPPUNIT_ASSERT(iter.key() != NULL);

       // Delete the element and check that key() returns NULL.
       h.remove(e);
       CPPUNIT_ASSERT(iter.key() == NULL);

       // Step the iterator and check that key() returns non-NULL.
       e = iter();
       CPPUNIT_ASSERT(e != NULL);
       CPPUNIT_ASSERT(iter.key() != NULL);

       // Step the iterator and check that key() returns non-NULL.
       e = iter();
       CPPUNIT_ASSERT(e != NULL);
       CPPUNIT_ASSERT(iter.key() != NULL);

       // Delete the element and check that key() returns NULL.
       h.remove(e);
       CPPUNIT_ASSERT(iter.key() == NULL);

       // Step the iterator and check that key() returns non-NULL.
       e = iter();
       CPPUNIT_ASSERT(e != NULL);
       CPPUNIT_ASSERT(iter.key() != NULL);

       // Step the iterator after the last element and check that
       // key() returns NULL.
       e = iter();
       CPPUNIT_ASSERT(e == NULL);
       CPPUNIT_ASSERT(iter.key() == NULL);

    } //removeKey()
开发者ID:ATHLSolutions,项目名称:sipxecs,代码行数:56,代码来源:UtlHashBagIterator.cpp


示例3: addVirtualOutputs

int MpTopologyGraph::addVirtualOutputs(MpResourceTopology& resourceTopology,
                                       UtlHashBag& newResources,
                                       UtlBoolean replaceNumInName,
                                       int resourceNum)
{
   int portsAdded = 0;
   MpResourceTopology::VirtualPortIterator portIter;
   UtlString realResourceName;
   int realPortIdx;
   UtlString virtualResourceName;
   int virtualPortIdx;

   resourceTopology.initVirtualOutputIterator(portIter);
   while (resourceTopology.getNextVirtualOutput(portIter,
                                                realResourceName, realPortIdx,
                                                virtualResourceName, virtualPortIdx)
          == OS_SUCCESS)
   {
      if(replaceNumInName)
      {
         MpResourceTopology::replaceNumInName(realResourceName, resourceNum);
         MpResourceTopology::replaceNumInName(virtualResourceName, resourceNum);
      }

      // Lookup real resource.
      MpResource *pResource = (MpResource*)newResources.find(&realResourceName);
      assert(pResource);
      if (!pResource)
      {
         continue;
      }

      // Check port index correctness. Note, that this check gracefully
      // handles case with realPortIdx equal -1.
      if (realPortIdx >= pResource->maxOutputs())
      {
         assert(!"Trying to map virtual port to non existing real port!");
         continue;
      }

      // Add entry to virtual ports map.
      // We need to create UtlVoidPtr wrapper for pResource, or it will be
      // destroyed on pair deletion.
      UtlContainablePair *pRealPort = new UtlContainablePair(new UtlVoidPtr(pResource),
                                                             new UtlInt(realPortIdx));
      UtlContainablePair *pVirtPort = new UtlContainablePair(new UtlString(virtualResourceName),
                                                             new UtlInt(virtualPortIdx));
      mVirtualOutputs.insertKeyAndValue(pVirtPort, pRealPort);
      portsAdded++;
   }
   resourceTopology.freeVirtualOutputIterator(portIter);

   return portsAdded;
}
开发者ID:John-Chan,项目名称:sipXtapi,代码行数:54,代码来源:MpTopologyGraph.cpp


示例4: testOneThousandInserts

      void testOneThousandInserts()
      {
         // Test case used to validate fix to issue XPL-169
         const int COUNT = 1000;
         const char stringPrefix[] = "Apofur81Kb";
         UtlHashBag bag;
         char tmpString[20];

         for( int i = 0; i < COUNT; i++)
         {
            sprintf(tmpString, "%s%d", stringPrefix, i);
            UtlString *stringToInsert = new UtlString();
            *stringToInsert = tmpString;

            CPPUNIT_ASSERT( ! bag.contains( stringToInsert ) );
            bag.insert( stringToInsert );
            CPPUNIT_ASSERT_EQUAL( i+1, (int)bag.entries() );

            for( unsigned int j = 0; j < bag.entries(); j++ )
            {
               // verify that all entries are indeed in the bag
               sprintf( tmpString, "%s%d", stringPrefix, j );
               UtlString stringTolookUp( tmpString );
               CPPUNIT_ASSERT_MESSAGE( tmpString, bag.contains( &stringTolookUp ) );
            }
         }
      }
开发者ID:ATHLSolutions,项目名称:sipxecs,代码行数:27,代码来源:UtlHashBag.cpp


示例5: testCollision

   /* Check for a problem that turned up in insert():  If an object
    * was inserted that should have been put at the end of a chain,
    * it was instead inserted at the beginning.
    *
    * This test detects the problem by inserting two objects which we arrange
    * to fall into the same bucket.  The object with the largest hash is
    * inserted second, so it should go at the end of the list, but instead
    * is inserted at the beginning.  The result is that the small-hash
    * object can't be seen by a selective HashBagIterator.
    *
    * The objects we use to exercise this case have to be tuned to the hash
    * algorithm of the objects and the algorithm
    * (UtlHashBag::bucketNumber) for turning hashes into bucket numbers.
    */
   void testCollision()
      {
         UtlHashBag bag;

         // For UtlInt's, the hash is the value.
         UtlInt small_hash_object(1);
         bag.insert(&small_hash_object);

         // put in some other objects
         UtlInt other_hash_object3(3);
         bag.insert(&other_hash_object3);
         UtlInt other_hash_object4(4);
         bag.insert(&other_hash_object4);
         UtlInt other_hash_object5(5);
         bag.insert(&other_hash_object5);

         UtlContainable* found;
         {
            // check that a keyed iterator sees the small_hash_object
            UtlHashBagIterator itor(bag, new UtlInt(1));
            found = itor();
            CPPUNIT_ASSERT(found == &small_hash_object);

            // and nothing else
            found = itor();
            CPPUNIT_ASSERT(found == NULL);
         }

         // We depend on the fact that a HashBag initially has 16 buckets and
         // folds hashes with XOR.  Under these conditions, 1 & 16 collide and
         // land in the same bucket.
         UtlInt large_hash_object(16);
         bag.insert(&large_hash_object);

         {
            // check that a keyed iterator sees the small_hash_object
            UtlHashBagIterator itor(bag, new UtlInt(1));
            found = itor();
            CPPUNIT_ASSERT(found == &small_hash_object);

            // and nothing else
            found = itor();
            CPPUNIT_ASSERT(found == NULL);
         }

         {
            // check that a keyed iterator sees the large_hash_object
            UtlHashBagIterator itor(bag, new UtlInt(16));
            found = itor();
            CPPUNIT_ASSERT(found == &large_hash_object);

            // and nothing else
            found = itor();
            CPPUNIT_ASSERT(found == NULL);
         }
      } // testCollision
开发者ID:ATHLSolutions,项目名称:sipxecs,代码行数:70,代码来源:UtlHashBagIterator.cpp


示例6: testIsEmpty

    /*!a  Test case for the isEmpty() method.
    *     The test data for this test are :-
    *        a) When the list has just been created.
    *        b) When the list has one entry in it
    *        c) When the list has multiple entries in it.
    *        e) When all the entries in a list have been removed using removeAll()
    */
    void testIsEmpty()
    {
        const int testCount = 4 ;
        const char* prefix = "Test the isEmpty() method when " ;
        const char* Msgs[] = { \
                "the list has just been created" , \
                "the list has just one entry in it", \
                "the list has multiple entries in it", \
                "all the list entries have been retreived using removeAll()" \
        } ;

        UtlHashBag newList ;
        UtlHashBag secondNewList ;
        UtlHashBag commonList_Clone ;

        // Add a single entry to the list.
        newList.insert(commonContainables[0])  ;
        UtlString uS1("Tester string") ;

        // populate the second list and then removeAll entries.
        secondNewList.insert(&uS1) ;
        UtlInt uI1 = UtlInt(232) ;
        secondNewList.insert(&uI1) ;
        secondNewList.insert(commonContainables[3]) ;

        secondNewList.removeAll() ;
        UtlHashBag* testLists[] = { \
                 &emptyList, &newList, &commonList,  &secondNewList \
        } ;

        bool exp[] = { true, false, false, true } ;
        for (int i = 0 ; i < testCount; i++)
        {
            string msg ;
            TestUtilities::createMessage(2, &msg, prefix, Msgs[i]) ;
            UtlBoolean act = testLists[i] -> isEmpty() ;
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (UtlBoolean)exp[i], act) ;
        }
    } // testIsEmpty
开发者ID:ATHLSolutions,项目名称:sipxecs,代码行数:46,代码来源:UtlHashBag.cpp


示例7: testClear

    /*!a test the removeAll() method.
    *
    *    The test data for this method is
    *        a) When the list is empty
    *        b) When the list has one entry.
    *        c) When the list multiple entries
    *        d) When removeAll has been called and entries are added again
    *        e) When the removeAll is called twice on the list.
    *        f) When the removeAll is call on a list that has muliple entries
    *           for the same key.
    */
    void testClear()
    {
        const int testCount = 6 ;
        const char* prefix = "Test the removeAll() method when :- " ;
        const char* Msgs[] = { \
               "the list is empty", \
               "the list has one entry", \
               "the list has multiple entries", \
               " has been called and entries are added again", \
               "removeAll() has already been called", \
               "removeAll() is called on list that has multiple matches" \
        } ;
        const char* suffix = " :- Verify number of entries after removeAll()" ;

        UtlHashBag uSingleList ;
        UtlHashBag uAddAfterClear ;
        UtlHashBag uDoubleClear ;

        // populate the hashtable with the 'common' values
        UtlHashBag commonList_Clone ;
        for (int i = 0 ; i < commonEntriesCount ; i++)
        {
            commonList_Clone.insert(commonContainables_Clone[i]) ;
        }
        // Add two values such that one of them has a 'value'
        // match already in the table and the other one has
        // a ref match.
        commonList_Clone.insert(commonContainables_Clone[3]) ;
        commonList_Clone.insert(commonContainables[5]) ;

        // Add a single entry to the list that is to be made up
        // of just one element
        uSingleList.insert(&commonString1) ;

        // call removeAll() on a list and then add entries again.
        uAddAfterClear.insert(&commonInt1) ;
        uAddAfterClear.insert(&commonString1) ;
        uAddAfterClear.removeAll() ;
        uAddAfterClear.insert(&commonInt2) ;

        // call removeAll on a list twice.
        uDoubleClear.insert(&commonString3) ;
        uDoubleClear.insert(&commonInt3) ;
        uDoubleClear.removeAll() ;

        UtlHashBag* testLists[] = { \
                     &emptyList, &uSingleList, &commonList, &uAddAfterClear, &uDoubleClear, &commonList_Clone
        } ;
        int expEntries[] = { 0 , 0, 0, 1, 0, 0} ;

        // since we are not calling removeAll for all the lists, do it outside the for loop for those
        // that require to be cleared.
        emptyList.removeAll() ;
        uSingleList.removeAll() ;
        commonList.removeAll() ;
        commonList_Clone.removeAll() ;
        // no removeAll() for uAddAfterClear
        uDoubleClear.removeAll() ;

        for ( int j = 0 ; j < testCount ; j++)
        {
            string msg ;
            TestUtilities::createMessage(3, &msg, prefix, Msgs[j], suffix) ;
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data() , expEntries[j], (int)testLists[j] -> entries()) ;

        }

    } //testClear()
开发者ID:ATHLSolutions,项目名称:sipxecs,代码行数:79,代码来源:UtlHashBag.cpp


示例8: addTopologyResources

int MpTopologyGraph::addTopologyResources(MpResourceTopology& resourceTopology,
                                          MpResourceFactory& resourceFactory,
                                          UtlHashBag& newResources,
                                          UtlBoolean replaceNumInName,
                                          int resourceNum)
{
    // Add the resources
    int resourceIndex = 0;
    MpResource* resourcePtr = NULL;
    MpResource* resourceArray[MAX_CONSTRUCTED_RESOURCES];
    UtlString resourceType;
    UtlString resourceName;
    MpConnectionID resourceConnId;
    int resourceStreamId;
    OsStatus result;
    while(resourceTopology.getResource(resourceIndex, resourceType, resourceName,
                                       resourceConnId, resourceStreamId) == OS_SUCCESS)
    {
        if(replaceNumInName)
        {
           MpResourceTopology::replaceNumInName(resourceName, resourceNum);
        }

        int numConstructorResources;
        OsStatus status;
        status = resourceFactory.newResource(resourceType, resourceName, MAX_CONSTRUCTED_RESOURCES,
                                             numConstructorResources, resourceArray);        
        if(status == OS_SUCCESS)
        {
           assert(numConstructorResources > 0);
           int arrayIndex;
           // We now can potentially get more than one resource back from the
           // constructor
           for(arrayIndex = 0; arrayIndex < numConstructorResources; arrayIndex++)
           {
              resourcePtr = resourceArray[arrayIndex];
              assert(resourcePtr);
              if(resourcePtr)
              {
#ifdef TEST_PRINT
                  printf("constructed and adding resource name: %s type: %s\n",
                         resourcePtr->getName().data(),
                         resourceType.data());
#endif
                  if(replaceNumInName && resourceConnId == MP_INVALID_CONNECTION_ID)
                  {
                     resourcePtr->setConnectionId(resourceNum);
                  }
                  else
                  {
                     resourcePtr->setConnectionId(resourceConnId);
                  }
                  resourcePtr->setStreamId(resourceStreamId);
                  newResources.insert(resourcePtr);
                  result = addResource(*resourcePtr, FALSE);
                  assert(result == OS_SUCCESS);
               }
           }
        }
        else
        {
           OsSysLog::add(FAC_MP, PRI_ERR, 
              "Failed to create resource type: %s name: %s status: %d",
              resourceType.data(), resourceName.data(), status);
        }
        resourceIndex++;
    }
    return(resourceIndex);
}
开发者ID:John-Chan,项目名称:sipXtapi,代码行数:69,代码来源:MpTopologyGraph.cpp


示例9: lock

void SipPublishContentMgr::getPublished(const char* resourceId,
                                        const char* eventTypeKey,
                                        UtlBoolean fullState,
                                        int& numContentTypes,
                                        HttpBody**& eventContent,
                                        SipPublishContentMgrDefaultConstructor**
                                        pDefaultConstructor)
{
    // Construct the key to look up.
    UtlString key;
    key.append(resourceId);
    key.append(CONTENT_KEY_SEPARATOR);
    key.append(eventTypeKey);

    lock();

    // Look up the key in the specific or default entries, as appropriate.
    UtlHashBag* bag = 
       resourceId ?
       (fullState ? &mContentEntries : &mPartialContentEntries) :
       (fullState ? &mDefaultContentEntries : &mDefaultPartialContentEntries);
    PublishContentContainer* container =
       dynamic_cast <PublishContentContainer*> (bag->find(&key));

    // If not found, return zero versions.
    if (container == NULL)
    {
       numContentTypes = 0;
       eventContent = new HttpBody*[0];
    }
    // Content for this event type exists.
    else
    {
        int num = container->mEventContent.entries();
        numContentTypes = num;

        HttpBody** contentCopies = new HttpBody*[num];
        eventContent = contentCopies;

        // Copy the contents into the array.
        for (int index = 0; index < num; index++)
        {
           eventContent[index] =
              new HttpBody(*dynamic_cast <HttpBody*>
                            (container->mEventContent.at(index)));
        }
    }

    // Return the default constructor, if any.
    if (pDefaultConstructor && !resourceId)
    {
       UtlContainable* defaultConstructor =
          (fullState ?
           mDefaultContentConstructors :
           mDefaultPartialContentConstructors).findValue(&key);
       *pDefaultConstructor =
          // Is there a default constructor?
          defaultConstructor ?
          // If so, make a copy of the constructor and return pointer to it.
          (dynamic_cast <SipPublishContentMgrDefaultConstructor*>
           (defaultConstructor))->copy() :
          // Otherwise, return NULL.
          NULL;
    }

    unlock();

    return;
}
开发者ID:ATHLSolutions,项目名称:sipxecs,代码行数:69,代码来源:SipPublishContentMgr.cpp


示例10: updateFile

OsStatus OsConfigDb::updateFile(const char* filename) const
{
   UtlString originalFileContents;
   long fileLength = OsFile::openAndRead(filename, originalFileContents);
   const char* unparsedBits = originalFileContents;
   int unparsedLength = originalFileContents.length();

   // Loop through and try to preserve comments, space and order
   int lineStart = 0;
   int lineEnd = 0;
   UtlHashBag writtenNames;
   UtlString newFileContents;
   UtlString name;
   UtlString value;
   UtlString newValue;

   while(lineStart < unparsedLength)
   {
      lineEnd = UtlTokenizer::nextDelim(unparsedBits, lineStart, unparsedLength, "\n\r");

      //printf("start: %d end: %d length: %d\n", lineStart, lineEnd, unparsedLength);

      UtlString oneLine(&unparsedBits[lineStart], lineEnd - lineStart);

      //printf("Line: <%s>\n", oneLine.data());

      // If line contains a parameter
      if(parseLine(oneLine, mCapitalizeName, filename, name, value))
      {
         //printf("name<%s> value<%s>\n", name.data(), value.data());
         if(get(name, newValue) == OS_SUCCESS &&
            !writtenNames.contains(&name))
         {
            //printf("Wrote name<%s>\n", name.data());
            // The parameter still exists in the configDb and we have not yet
            // written it out, write the potentially changed value
            newFileContents.appendFormat("%s : %s\n", name.data(), newValue.data());

            // Save names/parameters written so that we can figure out what has not
            // been written out
            writtenNames.insert(new UtlString(name));
         }
         // else the parameter was removed, do nothing
      }
   
      // The line was a comment or blank line, write it back out the same
      else
      {
         newFileContents.appendFormat("%s\n", oneLine.data());
      }

      lineStart = lineEnd + 1;
   }

   int paramIndex;
   int paramCount = numEntries();
   DbEntry* paramEntry;

   for (paramIndex = 0; paramIndex < paramCount; paramIndex++)
   {
      paramEntry = (DbEntry*) mDb.at(paramIndex);

      removeNewlineReturns(paramEntry->key);
      removeNewlineReturns(paramEntry->value);

      // We have not written the value yet
      if(!writtenNames.contains(&(paramEntry->key)))
      {
          newFileContents.appendFormat("%s : %s\n", paramEntry->key.data(), paramEntry->value.data());
          writtenNames.insert(new UtlString(paramEntry->key));
      }
   }

   fileLength = OsFile::openAndWrite(filename, newFileContents);
 
   writtenNames.destroyAll();

   return(fileLength > 0 ? OS_SUCCESS : OS_INVALID_ARGUMENT);
}
开发者ID:John-Chan,项目名称:sipXtapi,代码行数:79,代码来源:OsConfigDb.cpp


示例11: osPrintf

int MpTopologyGraph::linkTopologyResources(MpResourceTopology& resourceTopology,
                                           UtlHashBag& newResources,
                                           UtlBoolean replaceNumInName,
                                           int resourceNum)
{
    // Link the resources
    int connectionIndex = 0;
    UtlString outputResourceName;
    UtlString inputResourceName;
    int outputResourcePortIndex;
    int inputResourcePortIndex;
    MpResource* outputResource = NULL;
    MpResource* inputResource = NULL;
    OsStatus result;
    UtlHashMap newConnectionIds;

#ifdef TEST_PRINT
    osPrintf("%d new resources in the list\n", newResources.entries());
    UtlHashBagIterator iterator(newResources);
    MpResource* containerResource = NULL;
    while(containerResource = (MpResource*) iterator())
    {
        osPrintf("found list resource: \"%s\" value: \"%s\"\n",
                 containerResource->getName().data(), containerResource->data());
    }
#endif

    while(resourceTopology.getConnection(connectionIndex,
                                         outputResourceName,
                                         outputResourcePortIndex,
                                         inputResourceName,
                                         inputResourcePortIndex) == OS_SUCCESS)
    {
        if(replaceNumInName)
        {
            resourceTopology.replaceNumInName(outputResourceName, resourceNum);
            resourceTopology.replaceNumInName(inputResourceName, resourceNum);
        }

        // Look in the container of new resources first as this is more 
        // efficient and new resources are not added immediately to a running
        // flowgraph
        outputResource = (MpResource*) newResources.find(&outputResourceName);
        if(outputResource == NULL)
        {
            result = lookupResource(outputResourceName, outputResource);
            if(result != OS_SUCCESS)
            {
                int virtPortIdx = outputResourcePortIndex>=0?outputResourcePortIndex:-1;
                int realPortIdx;
                result = lookupVirtualOutput(outputResourceName, virtPortIdx,
                                             outputResource, realPortIdx);
                if (result == OS_SUCCESS && outputResourcePortIndex>=0)
                {
                   outputResourcePortIndex = realPortIdx;
                }
            }
            assert(result == OS_SUCCESS);
        }
        inputResource = (MpResource*) newResources.find(&inputResourceName);
        if(inputResource == NULL)
        {
            result = lookupResource(inputResourceName, inputResource);
            if(result != OS_SUCCESS)
            {
                int virtPortIdx = inputResourcePortIndex>=0?inputResourcePortIndex:-1;
                int realPortIdx;
                result = lookupVirtualInput(inputResourceName, virtPortIdx,
                                            inputResource, realPortIdx);
                if (result == OS_SUCCESS && inputResourcePortIndex>=0)
                {
                   inputResourcePortIndex = realPortIdx;
                }
            }
            assert(result == OS_SUCCESS);
        }
        assert(outputResource);
        assert(inputResource);

        if(outputResource && inputResource)
        {
            if(outputResourcePortIndex == MpResourceTopology::MP_TOPOLOGY_NEXT_AVAILABLE_PORT)
            {
                outputResourcePortIndex = outputResource->reserveFirstUnconnectedOutput();
                assert(outputResourcePortIndex >= 0);
            }
            else if(outputResourcePortIndex < MpResourceTopology::MP_TOPOLOGY_NEXT_AVAILABLE_PORT)
            {
                // First see if a real port is already in the dictionary
                UtlInt searchKey(outputResourcePortIndex);
                UtlInt* foundValue = NULL;
                if((foundValue = (UtlInt*) newConnectionIds.findValue(&searchKey)))
                {
                    // Use the mapped index
                    outputResourcePortIndex = foundValue->getValue();
                }
                else
                {
                    // Find an available port and add it to the map
                    int realPortNum = outputResource->reserveFirstUnconnectedOutput();
//.........这里部分代码省略.........
开发者ID:John-Chan,项目名称:sipXtapi,代码行数:101,代码来源:MpTopologyGraph.cpp


示例12: testFiltered

      void testFiltered()
      {
         UtlString key1a("key1");
         UtlString key1b("key1");
         UtlString key2("key2");
         UtlString key3("key3");

         UtlHashBag theBag;
         theBag.insert(&key1a);
         theBag.insert(&key1b);
         theBag.insert(&key2);
         theBag.insert(&key3);

         UtlString* content;

         {
            UtlString filter("key2");
            UtlHashBagIterator each(theBag,&filter);

            int foundMask;
            foundMask = 0;
            while ((content = (UtlString*)each()))
            {
               if ( &key1a == content )
               {
                  CHECK_FOUND(foundMask,0x0001);
               }
               else if ( &key1b == content )
               {
                  CHECK_FOUND(foundMask,0x0002);
               }
               else if ( &key2 == content )
               {
                  CHECK_FOUND(foundMask,0x0004);
               }
               else if ( &key3 == content )
               {
                  CHECK_FOUND(foundMask,0x0008);
               }
               else
               {
                  CPPUNIT_FAIL("Unknown element returned");
               }
            }
            CPPUNIT_ASSERT_MESSAGE("Expected element not found",0x0004==foundMask);
         }
         {
            UtlString filter("key1");
            UtlHashBagIterator each(theBag,&filter);

            int foundMask;
            foundMask = 0;
            while ((content = (UtlString*)each()))
            {
               if ( &key1a == content )
               {
                  CHECK_FOUND(foundMask,0x0001);
               }
               else if ( &key1b == content )
               {
                  CHECK_FOUND(foundMask,0x0002);
               }
               else if ( &key2 == content )
               {
                  CHECK_FOUND(foundMask,0x0004);
               }
               else if ( &key3 == content )
               {
                  CHECK_FOUND(foundMask,0x0008);
               }
               else
               {
                  CPPUNIT_FAIL("Unknown element returned");
               }
            }
            CPPUNIT_ASSERT_MESSAGE("Expected element not found",0x0003==foundMask);
         }
         {
            UtlString filter("key1");
            UtlHashBagIterator each(theBag,&filter);

            int foundMask;
            foundMask = 0;

            UtlString* removed = (UtlString*)theBag.remove(&filter);
            if ( &key1a == removed )
            {
               CHECK_FOUND(foundMask,0x0001);
            }
            else if ( &key1b == removed )
            {
               CHECK_FOUND(foundMask,0x0002);
            }
            else
            {
               CPPUNIT_FAIL("Unknown element removed");
            }

            while ((content = (UtlString*)each()))
            {
//.........这里部分代码省略.........
开发者ID:ATHLSolutions,项目名称:sipxecs,代码行数:101,代码来源:UtlHashBagIterator.cpp


示例13: testAdvancingOperator_And_KeyMethod

    /*!a Test case for the () operator and the key() method.
    *
    *    The test data for this test is :-
    *       1) The next entry is a UtlString
    *       2) The next entry is a UtlInt
    *       3) The next entry is the last entry
    *       4) All entries have been read
    */
    void testAdvancingOperator_And_KeyMethod()
    {
        const int testCount = 5;
        const char* prefix = "Verify the () operator " ;
        const char* prefix_for_key = "Verify the key() method " ;
        const char* Msgs[] = { \
                     "when the entry is the first of two value matches of UtlString type", \
                     "when the entry is the first of two reference matches of UtlInt type", \
                     "when the entry is a unique Containable", \
                     "when the entry is the second of two reference matches of UtlInt type", \
                     "when the entry is the second of two value matches of UtlString type" \
        } ;

        // Create a Hashtable such that it has one unique element (commonString2) ,
        // 2 elements that has value matches (commonString1 / commonString1_clone) ,
        // and 2 elements that *ARE* the same (commonInt1)
        UtlHashBag testList ;
        testList.insert(&commonString1) ;
        testList.insert(&commonInt1) ;
        testList.insert(&commonString1_clone) ;
        testList.insert(&commonString2) ;
        testList.insert(&commonInt1) ;

        UtlContainable* exp[] = { \
                          &commonString1 , &commonInt1, &commonString2, &commonInt1, &commonString1_clone
        } ;
        int expEntries = testCount;

        UtlHashBagIterator iter(testList) ;
        UtlContainable* act ;
        UtlContainable* expected_value_for_key_method ;
        string msg ;

        // Test the key method when the iterator has been reset.
        iter.reset() ;
        act = iter.key() ;
        TestUtilities::createMessage(2, &msg, prefix, "when the iterator has been reset") ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (void*)NULL, (void*)act) ;

        // Now iterate through the whole iterator and verify that all the items are
        // retreived. The () operator retreives the next item in the list. The
        // key item should retreive the item under the current position. (That is,
        // the key() method should always return what the previous () returned)
        for (int i = 0 ; i < testCount ; i++)
        {
             act = iter() ;
             expected_value_for_key_method = act;
             const char* curMessage = "";
             bool wasFound = false ;
             // We dont care about which item matches where. We only want to make sure
             // that each item *IS* retreived once and *ONLY* once.
             for (int j =0 ; j < testCount; j++)
             {
                 // If the item was already found during a previous iteration,
                 // we would have set the exp. value to NULL. so ignore all NULL
                 // expected values.
                 // The idea behind this is illustrated with the following example.
                 // Let us say that invoking foo.search(bar) can return either return
                 // either 90, 100 or 120 on the first search(either return is valid).
                 // Let's say that it returns 100. But if foo.search(bar) is invoked the
                 // second time, it should only return 90 or 120. So setting the element
                 // of the expected array that used to contain 100 to NULL means that
                 // that '100' is no longer a valid expected value.
                 if (exp[j] != NULL && act == exp[j])
                 {
                     wasFound = true ;
                     exp[j] = NULL ;
                     // Unlike traditional tests in which we know before hand the message
                     // for a particular iteration, in this case, the message is constructed
                     // based on the return value.
                     curMessage = Msgs[j] ;
                     break ;
                 }
              }
              if (!wasFound)
              {
                  curMessage = " :- One of the expected items was not retreived" \
                                  " using an indexing operator" ;
              }
              TestUtilities::createMessage(3, &msg, prefix, curMessage, " :- Verify return value") ;
              CPPUNIT_ASSERT_MESSAGE(msg.data(), wasFound) ;
              TestUtilities::createMessage(3, &msg, prefix, curMessage, " :- Verify that the number of entries has not changed") ;
              CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expEntries, (int)testList.entries()) ;
              // Verfiy that using the key() method retreives the value at the current position.
              // without repositioning the iterator.
              act = iter.key() ;
              TestUtilities::createMessage(2, &msg, prefix_for_key, curMessage) ;
              CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expected_value_for_key_method, act) ;
        }

        // Test the () operator when the whole list has been iterated
        act = iter() ;
//.........这里部分代码省略.........
开发者ID:ATHLSolutions,项目名称:sipxecs,代码行数:101,代码来源:UtlHashBagIterator.cpp


示例14: testRemoveReference

   void testRemoveReference()
      {
         // the following two entries collide if the initial bucket size is 16
         UtlInt int1(1);
         UtlInt int16(16);

         UtlInt int2a(2);
         UtlInt int2b(2);
         UtlInt int3(3);

         UtlHashBag bag;

         CPPUNIT_ASSERT( bag.numberOfBuckets() == 16 ); // check assumption of collision

         // Load all the test objects
         CPPUNIT_ASSERT( bag.insert(&int1) == &int1 );
         CPPUNIT_ASSERT( bag.insert(&int16) == &int16 );
         CPPUNIT_ASSERT( bag.insert(&int2a) == &int2a );
         CPPUNIT_ASSERT( bag.insert(&int2b) == &int2b );
         CPPUNIT_ASSERT( bag.insert(&int3) == &int3 );

         // Check that everything is there
         CPPUNIT_ASSERT( bag.entries() == 5 );
         CPPUNIT_ASSERT( bag.contains(&int1) );
         CPPUNIT_ASSERT( bag.contains(&int16) );
         CPPUNIT_ASSERT( bag.contains(&int2a) ); // cannot test for 2a and 2b independently
         CPPUNIT_ASSERT( bag.contains(&int3) );

         // Take entry 1 out (might collide w/ 16)
         CPPUNIT_ASSERT( bag.removeReference(&int1) == &int1 );

         // Check that everything except entry 1 is still there, and that 1 is gone
         CPPUNIT_ASSERT( bag.entries() == 4 );
         CPPUNIT_ASSERT( ! bag.contains(&int1) );
         CPPUNIT_ASSERT( bag.contains(&int16) );
         CPPUNIT_ASSERT( bag.contains(&int2a) );// cannot test for 2a and 2b independently
         CPPUNIT_ASSERT( bag.contains(&int3) );

         // Put entry 1 back in (so that 16 will collide w/ it again)
         CPPUNIT_ASSERT( bag.insert(&int1) == &int1 );

         // Check that everything is there
         CPPUNIT_ASSERT( bag.entries() == 5 );
         CPPUNIT_ASSERT( bag.contains(&int1) );
         CPPUNIT_ASSERT( bag.contains(&int16) );
         CPPUNIT_ASSERT( bag.contains(&int2a) );
         CPPUNIT_ASSERT( bag.contains(&int3) );

         // Take entry 16 out (might collide w/ 1)
         CPPUNIT_ASSERT( bag.removeReference(&int16) == &int16 );

         // Check that everything except entry 16 is still there, and that 16 is gone
         CPPUNIT_ASSERT( bag.entries() == 4 );
         CPPUNIT_ASSERT( bag.contains(&int1) );
         CPPUNIT_ASSERT( ! bag.contains(&int16) );
         CPPUNIT_ASSERT( bag.contains(&int2a) );// cannot test for 2a and 2b independently
         CPPUNIT_ASSERT( bag.contains(&int3) );

         // remove 2a (and ensure that you don't get back 2b)
         CPPUNIT_ASSERT( bag.removeReference(&int2a) == &int2a );

         // Check that everything that should be is still there
         CPPUNIT_ASSERT( bag.entries() == 3 );
         CPPUNIT_ASSERT( bag.contains(&int1) );
         CPPUNIT_ASSERT( ! bag.contains(&int16) );
         CPPUNIT_ASSERT( bag.find(&int2a) == &int2b ); // equal values, but now there's only one
         CPPUNIT_ASSERT( bag.contains(&int3) );

         // remove 3 (no collision for this one)
         CPPUNIT_ASSERT( bag.removeReference(&int3) == &int3 );

         // Check that everything that should be is still there
         CPPUNIT_ASSERT( bag.entries() == 2 );
         CPPUNIT_ASSERT( bag.contains(&int1) );
         CPPUNIT_ASSERT( ! bag.contains(&int16) );
         CPPUNIT_ASSERT( bag.find(&int2a) == &int2b ); // equal values, but now there's only one
         CPPUNIT_ASSERT( ! bag.contains(&int3) );

         // remove 3 again - should fail this time
         CPPUNIT_ASSERT( bag.removeReference(&int3) == NULL );

         // Check that everything that should be is still there
         CPPUNIT_ASSERT( bag.entries() == 2 );
         CPPUNIT_ASSERT( bag.contains(&int1) );
         CPPUNIT_ASSERT( ! bag.contains(&int16) );
         CPPUNIT_ASSERT( bag.find(&int2a) == &int2b ); // equal values, but now there's only one
         CPPUNIT_ASSERT( ! bag.contains(&int3) );

      }
开发者ID:ATHLSolutions,项目名称:sipxecs,代码行数:89,代码来源:UtlHashBag.cpp


示例15: testClearAndDestroy

    /*!a Test case to test the DestroyAll()
    *    method.
    */
    void testClearAndDestroy()
    {
        const int testCount = 3 ;
        int cCountBefore = UtlContainableTestStub :: getCount() ;
        const char* prefix  = "test the destroyAll() method " ;
        const char* suffix1  = " :- sanity check to double check that the counter was incremented for every new() call" ;
        const char* suffix2 = " :- Verify that all entries are removed and the objects are deleted" ;

        UtlContainableTestStub* uStub ;
        UtlContainableTestStub* uStubPtr ;
        UtlContainableTestStub* uStubPtr2 ;
        uStub = new UtlContainableTestStub(0) ;
        uStubPtr = new UtlContainableTestStub(201) ;
        uStubPtr2 = new UtlContainableTestStub(201) ;
        emptyList.insert(uStub) ;
        emptyList.insert(uStubPtr) ;
        emptyList.insert(uStubPtr2) ;

        cCountBefore = UtlContainableTestStub :: getCount() - cCountBefore ;
        emptyList.destroyAll() ;
        int cCountAfter = UtlContainableTestStub :: getCount() ;

        string msg ;
        // Make sure that static count was incremented for every instance
        // of the TestStub that was created.
        TestUtilities::createMessage(2, &msg, prefix, suffix1) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(),  testCount, cCountBefore) ;

        // Verify that the list has no entries left after destroyAll()
        // and also ensure that all the TestStub instances were deleted.
        TestUtilities::createMessage(2, &msg, prefix, suffix2) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, cCountAfter) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, (int)emptyList.entries()) ;
    } //testClearAndDestroy
开发者ID:ATHLSolutions,项目名称:sipxecs,代码行数:37,代码来源:UtlHashBag.cpp


示例16: testRemove

    /*!a Test case for testRemove()
    *
    *     The Test data for this test case is
    *          a) is an entry's reference
    *          b) is an entry's value(not reference)
    *          c) is the first of multiple matches and is the value match
    *          d) is the second of multiple matches.
    *          e) has no match at all
    */
    void testRemove()
    {
        int testCount = 4 ;
        const char* prefix = "test the remove(UtlContainable* c) method where c " ;
        const char* Msgs[] = { \
               "is an entry's reference ", \
               "is an entry's value(not reference) ", \
               "is first of multiple value matches ", \
               "has no match at all " \
        } ;
        const char* suffix1 = " :- Verify returned value" ;
        const char* suffix2 = " :- Verify total entries" ;

        // Insert a new value such that its value matches(isEqual to)
        // one of the existing items
        commonList.insert(commonContainables_Clone[4]) ;
        UtlString notExistContainable("This cannot and willnot exist");

        UtlContainable* dataForRemove[] = { \
                           commonContainables[0], \
                           commonContainables_Clone[2], \
                           commonContainables[4], \
                           &notExistContainable \
        } ;

        int totalEnt = commonEntriesCount + 1;

        UtlBoolean expectedReturnValues[] = { \
            true, true, true, false \
        } ;

        int entriesValue[] = { --totalEnt, --totalEnt, --totalEnt, totalEnt } ;

        totalEnt = commonEntriesCount + 1;


        for (int i = 0 ; i < testCou 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ UtlInt类代码示例发布时间:2022-05-31
下一篇:
C++ UtlDList类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap