searchengine/cpix/tsrc/perfmetrics/src/testvector.cpp
changeset 0 671dee74050a
equal deleted inserted replaced
-1:000000000000 0:671dee74050a
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 #include <iostream>
       
    18 
       
    19 
       
    20 #include "testvector.h"
       
    21 
       
    22 TestVector::TestVector()
       
    23     : testName("plain"),
       
    24       create(1),
       
    25       bufferSize(32*1024), // TODO: bind to constant  
       
    26       numPreindexedItems(0),
       
    27       maxInputSize(10),
       
    28       lumpSize(5),
       
    29       first(1),
       
    30       last(1),
       
    31       search(0),
       
    32       incrementalSearch(0),
       
    33       minIncrementalLength(3),
       
    34       suggestionSearch(0),
       
    35       minSuggestionLength(3),
       
    36       takeIdxSnapshot(0),
       
    37       addLasts(1),
       
    38       delReAddLasts(1),
       
    39       updateLasts(1)
       
    40 {
       
    41     ;
       
    42 }
       
    43 
       
    44 
       
    45 int (TestVector::* IntMembers[]) = {
       
    46     &TestVector::create,
       
    47     &TestVector::bufferSize, 
       
    48     &TestVector::numPreindexedItems,
       
    49     &TestVector::maxInputSize,
       
    50     &TestVector::lumpSize,
       
    51     &TestVector::first,
       
    52     &TestVector::last,
       
    53     &TestVector::search,
       
    54     &TestVector::incrementalSearch,
       
    55     &TestVector::minIncrementalLength,
       
    56     &TestVector::suggestionSearch,
       
    57     &TestVector::minSuggestionLength,
       
    58     &TestVector::takeIdxSnapshot,
       
    59     &TestVector::addLasts,
       
    60     &TestVector::delReAddLasts,
       
    61     &TestVector::updateLasts
       
    62 };
       
    63 
       
    64 
       
    65 std::istream & TestVector::read(std::istream & is)
       
    66 {
       
    67     if (is)
       
    68         {
       
    69             testName = readStr(is);
       
    70         }
       
    71             
       
    72     for (size_t i = 0; 
       
    73          i < sizeof(IntMembers) / sizeof(int (TestVector::*)) && is;
       
    74          ++i)
       
    75         {
       
    76             this->*IntMembers[i] = readInt(is);
       
    77         }
       
    78 
       
    79     while (is)
       
    80         {
       
    81             std::string 
       
    82                 queryTerm = readStr(is);
       
    83 
       
    84             if (is)
       
    85                 {
       
    86                     queryTerms.push_back(queryTerm);
       
    87                 }
       
    88         }
       
    89 
       
    90     return is;
       
    91 }
       
    92 
       
    93 
       
    94 int TestVector::readInt(std::istream   & is)
       
    95 {
       
    96     std::string
       
    97         line;
       
    98 
       
    99     nextLine(is,
       
   100              line);
       
   101 
       
   102     int
       
   103         rv = 0;
       
   104 
       
   105     if (is)
       
   106         {
       
   107             std::strstream
       
   108                 dummy(const_cast<char*>(line.c_str()),
       
   109                       line.length());
       
   110             dummy >> rv;
       
   111         }
       
   112 
       
   113     return rv;
       
   114 }
       
   115 
       
   116 
       
   117 std::string TestVector::readStr(std::istream   & is)
       
   118 {
       
   119     std::string
       
   120         line;
       
   121 
       
   122     nextLine(is,
       
   123              line);
       
   124     
       
   125     if (line.length() > 0)
       
   126         {
       
   127             if (line[line.length()-1] == '\r')
       
   128                 {
       
   129                     line = line.substr(0,
       
   130                                        line.length() - 1);
       
   131                 }
       
   132         }
       
   133 
       
   134     return line;
       
   135 }
       
   136 
       
   137 
       
   138 void TestVector::nextLine(std::istream   & is,
       
   139                           std::string    & line)
       
   140 {
       
   141     while (getline(is, line))
       
   142         {
       
   143             if (line.length() > 0
       
   144                 && line[0] != '#'
       
   145                 && line[0] != '\r')
       
   146                 {
       
   147                     break;
       
   148                 }
       
   149             else
       
   150                 {
       
   151                     line = "";
       
   152                 }
       
   153         }
       
   154 }
       
   155 
       
   156 
       
   157 
       
   158 std::istream & operator>>(std::istream & is,
       
   159                           TestVector   & tv)
       
   160 {
       
   161     return tv.read(is);
       
   162 }