diff options
author | Bernard Normier <bernard@zeroc.com> | 2007-02-01 17:09:49 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2007-02-01 17:09:49 +0000 |
commit | abada90e3f84dc703b8ddc9efcbed8a946fadead (patch) | |
tree | 2c6f9dccd510ea97cb927a7bd635422efaae547a /cpp/demo/Freeze | |
parent | removing trace message (diff) | |
download | ice-abada90e3f84dc703b8ddc9efcbed8a946fadead.tar.bz2 ice-abada90e3f84dc703b8ddc9efcbed8a946fadead.tar.xz ice-abada90e3f84dc703b8ddc9efcbed8a946fadead.zip |
Expanded tabs into spaces
Diffstat (limited to 'cpp/demo/Freeze')
-rw-r--r-- | cpp/demo/Freeze/backup/Client.cpp | 78 | ||||
-rw-r--r-- | cpp/demo/Freeze/bench/Client.cpp | 794 | ||||
-rw-r--r-- | cpp/demo/Freeze/library/Client.cpp | 6 | ||||
-rw-r--r-- | cpp/demo/Freeze/library/Collocated.cpp | 10 | ||||
-rw-r--r-- | cpp/demo/Freeze/library/Library.ice | 16 | ||||
-rw-r--r-- | cpp/demo/Freeze/library/LibraryI.cpp | 132 | ||||
-rw-r--r-- | cpp/demo/Freeze/library/LibraryI.h | 4 | ||||
-rw-r--r-- | cpp/demo/Freeze/library/Parser.cpp | 440 | ||||
-rw-r--r-- | cpp/demo/Freeze/library/RunParser.cpp | 176 | ||||
-rw-r--r-- | cpp/demo/Freeze/library/Server.cpp | 4 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/Client.cpp | 6 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/Collocated.cpp | 10 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/Parser.cpp | 396 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/PhoneBookI.cpp | 34 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/RunParser.cpp | 176 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/Server.cpp | 4 |
16 files changed, 1143 insertions, 1143 deletions
diff --git a/cpp/demo/Freeze/backup/Client.cpp b/cpp/demo/Freeze/backup/Client.cpp index 89008fa26b2..4630a15858f 100644 --- a/cpp/demo/Freeze/backup/Client.cpp +++ b/cpp/demo/Freeze/backup/Client.cpp @@ -38,51 +38,51 @@ main(int argc, char* argv[]) const int size = 10000; if(m.size() == 0) - { - cout << "********* Creating new map ***********" << endl; - Freeze::TransactionHolder txHolder(connection); - - IceUtil::Time time = IceUtil::Time::now(); - IceUtil::Int64 ms = time.toMilliSeconds(); - - for(int i = 0; i < size; ++i) - { - m.insert(IntLongMap::value_type(i, ms)); - } - txHolder.commit(); + { + cout << "********* Creating new map ***********" << endl; + Freeze::TransactionHolder txHolder(connection); + + IceUtil::Time time = IceUtil::Time::now(); + IceUtil::Int64 ms = time.toMilliSeconds(); + + for(int i = 0; i < size; ++i) + { + m.insert(IntLongMap::value_type(i, ms)); + } + txHolder.commit(); } cout << "Updating map" << endl; for(;;) { - int count = 0; - - Freeze::TransactionHolder txHolder(connection); - IceUtil::Time time = IceUtil::Time::now(); - IceUtil::Int64 ms = time.toMilliSeconds(); - - IntLongMap::iterator p = m.begin(); - IceUtil::Int64 oldMs = p->second; - do - { - if(p->second != oldMs) - { - cerr << "old time (ms) == " << oldMs << endl; - cerr << "current current (ms) == " << p->second << endl; - } - - test(p->second == oldMs); - p.set(ms); - count++; - } while(++p != m.end()); - - cout << "Read " << IceUtil::Time::milliSeconds(oldMs).toDateTime() << " in all records;" - << " updating with " << time.toDateTime() << " ... " << flush; - - txHolder.commit(); - cout << "done" << endl; - test(count == size); + int count = 0; + + Freeze::TransactionHolder txHolder(connection); + IceUtil::Time time = IceUtil::Time::now(); + IceUtil::Int64 ms = time.toMilliSeconds(); + + IntLongMap::iterator p = m.begin(); + IceUtil::Int64 oldMs = p->second; + do + { + if(p->second != oldMs) + { + cerr << "old time (ms) == " << oldMs << endl; + cerr << "current current (ms) == " << p->second << endl; + } + + test(p->second == oldMs); + p.set(ms); + count++; + } while(++p != m.end()); + + cout << "Read " << IceUtil::Time::milliSeconds(oldMs).toDateTime() << " in all records;" + << " updating with " << time.toDateTime() << " ... " << flush; + + txHolder.commit(); + cout << "done" << endl; + test(count == size); } connection->close(); diff --git a/cpp/demo/Freeze/bench/Client.cpp b/cpp/demo/Freeze/bench/Client.cpp index 07b95e14f38..67f71de2a2e 100644 --- a/cpp/demo/Freeze/bench/Client.cpp +++ b/cpp/demo/Freeze/bench/Client.cpp @@ -36,20 +36,20 @@ public: void start() { - _stopped = false; - _start = IceUtil::Time::now(); + _stopped = false; + _start = IceUtil::Time::now(); } IceUtil::Time stop() { - if(!_stopped) - { - _stopped = true; - _stop = IceUtil::Time::now(); - } + if(!_stopped) + { + _stopped = true; + _stop = IceUtil::Time::now(); + } - return _stop - _start; + return _stop - _start; } private: @@ -75,23 +75,23 @@ class RandomGenerator : public Generator public: RandomGenerator(int seed, int max) : - _max(max) + _max(max) { - srand(seed); + srand(seed); } virtual int next() { - return rand() % _max; + return rand() % _max; } virtual string toString() { - ostringstream os; - os << "random(" << _max << ")"; - return os.str(); + ostringstream os; + os << "random(" << _max << ")"; + return os.str(); } private: @@ -104,30 +104,30 @@ class SequentialGenerator : public Generator public: SequentialGenerator(int min, int max) : - _min(min), - _max(max), - _current(0) + _min(min), + _max(max), + _current(0) { } virtual int next() { - int n = _current; - ++_current; - if(_current > _max) - { - _current = _min; - } - return n; + int n = _current; + ++_current; + if(_current > _max) + { + _current = _min; + } + return n; } virtual string toString() { - ostringstream os; - os << ((_max - _min)+1); - return os.str(); + ostringstream os; + os << ((_max - _min)+1); + return os.str(); } private: @@ -157,68 +157,68 @@ private: void IntIntMapIndexTest(IndexedIntIntMap&); template<class T> void IntIntMapTest(const string& mapName, T* = 0) { - T m(_connection, mapName); - // - // Populate the database. - // - int i; - _watch.start(); - { - Freeze::TransactionHolder txHolder(_connection); - for(i = 0; i < _repetitions; ++i) - { + T m(_connection, mapName); + // + // Populate the database. + // + int i; + _watch.start(); + { + Freeze::TransactionHolder txHolder(_connection); + for(i = 0; i < _repetitions; ++i) + { #if defined(__BCPLUSPLUS__) || (defined(_MSC_VER) && (_MSC_VER < 1310)) - m.put(T::value_type(i, i)); + m.put(T::value_type(i, i)); #else - m.put(typename T::value_type(i, i)); + m.put(typename T::value_type(i, i)); #endif - } - txHolder.commit(); - } - IceUtil::Time total = _watch.stop(); - IceUtil::Time perRecord = total / _repetitions; - - cout << "\ttime for " << _repetitions << " writes: " << total * 1000 << "ms" << endl; - cout << "\ttime per write: " << perRecord * 1000 << "ms" << endl; - - // - // Read each record. - // - _watch.start(); - for(i = 0; i < _repetitions; ++i) - { - typename T::iterator p = m.find(i); - test(p != m.end()); - test(p->second == i); - } - total = _watch.stop(); - perRecord = total / _repetitions; - - cout << "\ttime for " << _repetitions << " reads: " << total * 1000 << "ms" << endl; - cout << "\ttime per read: " << perRecord * 1000 << "ms" << endl; - - // - // Optional index sub-test - // - IntIntMapIndexTest(m); - - // - // Remove each record. - // - _watch.start(); - { - Freeze::TransactionHolder txHolder(_connection); - for(i = 0; i < _repetitions; ++i) - { - m.erase(i); - } - txHolder.commit(); - } - total = _watch.stop(); - perRecord = total / _repetitions; - - cout << "\ttime for " << _repetitions << " removes: " << total * 1000 << "ms" << endl; - cout << "\ttime per remove: " << perRecord * 1000 << "ms" << endl; + } + txHolder.commit(); + } + IceUtil::Time total = _watch.stop(); + IceUtil::Time perRecord = total / _repetitions; + + cout << "\ttime for " << _repetitions << " writes: " << total * 1000 << "ms" << endl; + cout << "\ttime per write: " << perRecord * 1000 << "ms" << endl; + + // + // Read each record. + // + _watch.start(); + for(i = 0; i < _repetitions; ++i) + { + typename T::iterator p = m.find(i); + test(p != m.end()); + test(p->second == i); + } + total = _watch.stop(); + perRecord = total / _repetitions; + + cout << "\ttime for " << _repetitions << " reads: " << total * 1000 << "ms" << endl; + cout << "\ttime per read: " << perRecord * 1000 << "ms" << endl; + + // + // Optional index sub-test + // + IntIntMapIndexTest(m); + + // + // Remove each record. + // + _watch.start(); + { + Freeze::TransactionHolder txHolder(_connection); + for(i = 0; i < _repetitions; ++i) + { + m.erase(i); + } + txHolder.commit(); + } + total = _watch.stop(); + perRecord = total / _repetitions; + + cout << "\ttime for " << _repetitions << " removes: " << total * 1000 << "ms" << endl; + cout << "\ttime per remove: " << perRecord * 1000 << "ms" << endl; } @@ -227,22 +227,22 @@ private: void generatedReadWithIndex(IndexedIntIntMap&, int, const GeneratorPtr&); template<class T> void generatedRead(T& m, int reads , const GeneratorPtr& gen) { - _watch.start(); - for(int i = 0; i < reads; ++i) - { - int key = gen->next(); - typename T::iterator p = m.find(key); - test(p != m.end()); - test(p->second == key); - } - IceUtil::Time total = _watch.stop(); - IceUtil::Time perRecord = total / reads; - - cout << "\ttime for " << reads << " reads of " << gen->toString() << " records: " << total * 1000 << "ms" - << endl; - cout << "\ttime per read: " << perRecord * 1000 << "ms" << endl; - - generatedReadWithIndex(m, reads, gen); + _watch.start(); + for(int i = 0; i < reads; ++i) + { + int key = gen->next(); + typename T::iterator p = m.find(key); + test(p != m.end()); + test(p->second == key); + } + IceUtil::Time total = _watch.stop(); + IceUtil::Time perRecord = total / reads; + + cout << "\ttime for " << reads << " reads of " << gen->toString() << " records: " << total * 1000 << "ms" + << endl; + cout << "\ttime per read: " << perRecord * 1000 << "ms" << endl; + + generatedReadWithIndex(m, reads, gen); } @@ -251,81 +251,81 @@ private: void Struct1Struct2MapIndexTest(IndexedStruct1Struct2Map&); template<class T> void Struct1Struct2MapTest(const string& mapName, T* = 0) { - T m(_connection, mapName); - - // - // Populate the database. - // - Struct1 s1; - Struct2 s2; - int i; - _watch.start(); - { - Freeze::TransactionHolder txHolder(_connection); - for(i = 0; i < _repetitions; ++i) - { - s1.l = i; - ostringstream os; - os << i; - s2.s = os.str(); - s2.s1 = s1; + T m(_connection, mapName); + + // + // Populate the database. + // + Struct1 s1; + Struct2 s2; + int i; + _watch.start(); + { + Freeze::TransactionHolder txHolder(_connection); + for(i = 0; i < _repetitions; ++i) + { + s1.l = i; + ostringstream os; + os << i; + s2.s = os.str(); + s2.s1 = s1; #if defined(__BCPLUSPLUS__) || (defined(_MSC_VER) && (_MSC_VER < 1310)) - m.put(T::value_type(s1, s2)); + m.put(T::value_type(s1, s2)); #else - m.put(typename T::value_type(s1, s2)); + m.put(typename T::value_type(s1, s2)); #endif - } - txHolder.commit(); - } - IceUtil::Time total = _watch.stop(); - IceUtil::Time perRecord = total / _repetitions; - - cout << "\ttime for " << _repetitions << " writes: " << total * 1000 << "ms" << endl; - cout << "\ttime per write: " << perRecord * 1000 << "ms" << endl; - - // - // Read each record. - // - _watch.start(); - for(i = 0; i < _repetitions; ++i) - { - s1.l = i; - typename T::iterator p = m.find(s1); - test(p != m.end()); - ostringstream os; - os << i; - test(p->second.s == os.str()); - } - total = _watch.stop(); - perRecord = total / _repetitions; - - cout << "\ttime for " << _repetitions << " reads: " << total * 1000 << "ms" << endl; - cout << "\ttime per read: " << perRecord * 1000 << "ms" << endl; - - // - // Optional index test - // - Struct1Struct2MapIndexTest(m); - - // - // Remove each record. - // - _watch.start(); - { - Freeze::TransactionHolder txHolder(_connection); - for(i = 0; i < _repetitions; ++i) - { - s1.l = i; - m.erase(s1); - } - txHolder.commit(); - } - total = _watch.stop(); - perRecord = total / _repetitions; - - cout << "\ttime for " << _repetitions << " removes: " << total * 1000 << "ms" << endl; - cout << "\ttime per remove: " << perRecord * 1000 << "ms" << endl; + } + txHolder.commit(); + } + IceUtil::Time total = _watch.stop(); + IceUtil::Time perRecord = total / _repetitions; + + cout << "\ttime for " << _repetitions << " writes: " << total * 1000 << "ms" << endl; + cout << "\ttime per write: " << perRecord * 1000 << "ms" << endl; + + // + // Read each record. + // + _watch.start(); + for(i = 0; i < _repetitions; ++i) + { + s1.l = i; + typename T::iterator p = m.find(s1); + test(p != m.end()); + ostringstream os; + os << i; + test(p->second.s == os.str()); + } + total = _watch.stop(); + perRecord = total / _repetitions; + + cout << "\ttime for " << _repetitions << " reads: " << total * 1000 << "ms" << endl; + cout << "\ttime per read: " << perRecord * 1000 << "ms" << endl; + + // + // Optional index test + // + Struct1Struct2MapIndexTest(m); + + // + // Remove each record. + // + _watch.start(); + { + Freeze::TransactionHolder txHolder(_connection); + for(i = 0; i < _repetitions; ++i) + { + s1.l = i; + m.erase(s1); + } + txHolder.commit(); + } + total = _watch.stop(); + perRecord = total / _repetitions; + + cout << "\ttime for " << _repetitions << " removes: " << total * 1000 << "ms" << endl; + cout << "\ttime per remove: " << perRecord * 1000 << "ms" << endl; } @@ -334,80 +334,80 @@ private: void Struct1Class1MapIndexTest(IndexedStruct1Class1Map&); template<class T> void Struct1Class1MapTest(const string& mapName, T* = 0) { - T m(_connection, mapName); - - // - // Populate the database. - // - Struct1 s1; - Class1Ptr c1 = new Class1(); - int i; - _watch.start(); - { - Freeze::TransactionHolder txHolder(_connection); - for(i = 0; i < _repetitions; ++i) - { - s1.l = i; - ostringstream os; - os << i; - c1->s = os.str(); + T m(_connection, mapName); + + // + // Populate the database. + // + Struct1 s1; + Class1Ptr c1 = new Class1(); + int i; + _watch.start(); + { + Freeze::TransactionHolder txHolder(_connection); + for(i = 0; i < _repetitions; ++i) + { + s1.l = i; + ostringstream os; + os << i; + c1->s = os.str(); #if defined(__BCPLUSPLUS__) || (defined(_MSC_VER) && (_MSC_VER < 1310)) - m.put(T::value_type(s1, c1)); + m.put(T::value_type(s1, c1)); #else - m.put(typename T::value_type(s1, c1)); + m.put(typename T::value_type(s1, c1)); #endif - } - txHolder.commit(); - } - IceUtil::Time total = _watch.stop(); - IceUtil::Time perRecord = total / _repetitions; - - cout << "\ttime for " << _repetitions << " writes: " << total * 1000 << "ms" << endl; - cout << "\ttime per write: " << perRecord * 1000 << "ms" << endl; - - // - // Read each record. - // - _watch.start(); - for(i = 0; i < _repetitions; ++i) - { - s1.l = i; - typename T::iterator p = m.find(s1); - test(p != m.end()); - ostringstream os; - os << i; - test(p->second->s == os.str()); - } - total = _watch.stop(); - perRecord = total / _repetitions; - - cout << "\ttime for " << _repetitions << " reads: " << total * 1000 << "ms" << endl; - cout << "\ttime per read: " << perRecord * 1000 << "ms" << endl; - - // - // Optional index test - // - - Struct1Class1MapIndexTest(m); - - // - // Remove each record. - // - _watch.start(); - { - Freeze::TransactionHolder txHolder(_connection); - for(i = 0; i < _repetitions; ++i) - { - s1.l = i; - m.erase(s1); - } - txHolder.commit(); - } - total = _watch.stop(); - perRecord = total / _repetitions; - - cout << "\ttime for " << _repetitions << " removes: " << total * 1000 << "ms" << endl; - cout << "\ttime per remove: " << perRecord * 1000 << "ms" << endl; + } + txHolder.commit(); + } + IceUtil::Time total = _watch.stop(); + IceUtil::Time perRecord = total / _repetitions; + + cout << "\ttime for " << _repetitions << " writes: " << total * 1000 << "ms" << endl; + cout << "\ttime per write: " << perRecord * 1000 << "ms" << endl; + + // + // Read each record. + // + _watch.start(); + for(i = 0; i < _repetitions; ++i) + { + s1.l = i; + typename T::iterator p = m.find(s1); + test(p != m.end()); + ostringstream os; + os << i; + test(p->second->s == os.str()); + } + total = _watch.stop(); + perRecord = total / _repetitions; + + cout << "\ttime for " << _repetitions << " reads: " << total * 1000 << "ms" << endl; + cout << "\ttime per read: " << perRecord * 1000 << "ms" << endl; + + // + // Optional index test + // + + Struct1Class1MapIndexTest(m); + + // + // Remove each record. + // + _watch.start(); + { + Freeze::TransactionHolder txHolder(_connection); + for(i = 0; i < _repetitions; ++i) + { + s1.l = i; + m.erase(s1); + } + txHolder.commit(); + } + total = _watch.stop(); + perRecord = total / _repetitions; + + cout << "\ttime for " << _repetitions << " removes: " << total * 1000 << "ms" << endl; + cout << "\ttime per remove: " << perRecord * 1000 << "ms" << endl; } void IntIntMapReadIndexTest(IntIntMap&) @@ -415,62 +415,62 @@ private: void IntIntMapReadIndexTest(IndexedIntIntMap&); template<class T> void IntIntMapReadTest(const string& mapName, T* = 0) { - T m(_connection, mapName); - - // - // Populate the database. - // - int i; - _watch.start(); - { - Freeze::TransactionHolder txHolder(_connection); - for(i = 0; i < _repetitions; ++i) - { + T m(_connection, mapName); + + // + // Populate the database. + // + int i; + _watch.start(); + { + Freeze::TransactionHolder txHolder(_connection); + for(i = 0; i < _repetitions; ++i) + { #if defined(__BCPLUSPLUS__) || (defined(_MSC_VER) && (_MSC_VER < 1310)) - m.put(T::value_type(i, i)); + m.put(T::value_type(i, i)); #else - m.put(typename T::value_type(i, i)); + m.put(typename T::value_type(i, i)); #endif - } - txHolder.commit(); - } - IceUtil::Time total = _watch.stop(); - IceUtil::Time perRecord = total / _repetitions; - - cout << "\ttime for " << _repetitions << " writes: " << total * 1000 << "ms" << endl; - cout << "\ttime per write: " << perRecord * 1000 << "ms" << endl; - - // - // Do some read tests. - // - generatedRead(m, _repetitions, new SequentialGenerator(1000, 1000)); - generatedRead(m, _repetitions, new SequentialGenerator(2000, 2009)); - generatedRead(m, _repetitions, new SequentialGenerator(3000, 3099)); - generatedRead(m, _repetitions, new SequentialGenerator(4000, 4999)); - - // - // Do a random read test. - // - generatedRead(m, _repetitions, new RandomGenerator(0, 10000)); - - // - // Remove each record. - // - /* - * For this test I don't want to remove the records because I - * want to examine the cache stats for the database. - * - _watch.start(); - for(i = 0; i < _repetitions; ++i) - { - m.erase(i); - } - total = _watch.stop(); - perRecord = total / _repetitions; - - cout << "\ttime for " << _repetitions << " removes: " << total * 1000 << "ms" << endl; - cout << "\ttime per remove: " << perRecord * 1000 << "ms" << endl; - */ + } + txHolder.commit(); + } + IceUtil::Time total = _watch.stop(); + IceUtil::Time perRecord = total / _repetitions; + + cout << "\ttime for " << _repetitions << " writes: " << total * 1000 << "ms" << endl; + cout << "\ttime per write: " << perRecord * 1000 << "ms" << endl; + + // + // Do some read tests. + // + generatedRead(m, _repetitions, new SequentialGenerator(1000, 1000)); + generatedRead(m, _repetitions, new SequentialGenerator(2000, 2009)); + generatedRead(m, _repetitions, new SequentialGenerator(3000, 3099)); + generatedRead(m, _repetitions, new SequentialGenerator(4000, 4999)); + + // + // Do a random read test. + // + generatedRead(m, _repetitions, new RandomGenerator(0, 10000)); + + // + // Remove each record. + // + /* + * For this test I don't want to remove the records because I + * want to examine the cache stats for the database. + * + _watch.start(); + for(i = 0; i < _repetitions; ++i) + { + m.erase(i); + } + total = _watch.stop(); + perRecord = total / _repetitions; + + cout << "\ttime for " << _repetitions << " removes: " << total * 1000 << "ms" << endl; + cout << "\ttime per remove: " << perRecord * 1000 << "ms" << endl; + */ } @@ -497,15 +497,15 @@ TestApp::IntIntMapIndexTest(IndexedIntIntMap& m) _watch.start(); for(int i = 0; i < _repetitions; ++i) { - IndexedIntIntMap::iterator p = m.findByValue(i); - test(p != m.end()); - test(p->second == i); + IndexedIntIntMap::iterator p = m.findByValue(i); + test(p != m.end()); + test(p->second == i); } IceUtil::Time total = _watch.stop(); IceUtil::Time perRecord = total / _repetitions; cout << "\ttime for " << _repetitions << " reverse (indexed) reads: " << total * 1000 << "ms" - << endl; + << endl; cout << "\ttime per reverse read: " << perRecord * 1000 << "ms" << endl; } @@ -515,16 +515,16 @@ TestApp::generatedReadWithIndex(IndexedIntIntMap& m, int reads, const GeneratorP _watch.start(); for(int i = 0; i < reads; ++i) { - int value = gen->next(); - IndexedIntIntMap::iterator p = m.findByValue(value); - test(p != m.end()); - test(p->second == value); + int value = gen->next(); + IndexedIntIntMap::iterator p = m.findByValue(value); + test(p != m.end()); + test(p->second == value); } IceUtil::Time total = _watch.stop(); IceUtil::Time perRecord = total / reads; cout << "\ttime for " << reads << " reverse (indexed) reads of " << gen->toString() << " records: " - << total * 1000 << "ms" << endl; + << total * 1000 << "ms" << endl; cout << "\ttime per reverse read: " << perRecord * 1000 << "ms" << endl; } @@ -536,23 +536,23 @@ TestApp::Struct1Struct2MapIndexTest(IndexedStruct1Struct2Map& m) _watch.start(); for(i = 0; i < _repetitions; ++i) { - ostringstream os; - os << i; + ostringstream os; + os << i; - IndexedStruct1Struct2Map::iterator p = m.findByS(os.str()); - test(p != m.end()); - test(p->first.l == i); - test(p->second.s1.l == i); + IndexedStruct1Struct2Map::iterator p = m.findByS(os.str()); + test(p != m.end()); + test(p->first.l == i); + test(p->second.s1.l == i); } for(i = 0; i < _repetitions; ++i) { - Struct1 s1; - s1.l = i; - IndexedStruct1Struct2Map::iterator p = m.findByS1(s1); - test(p != m.end()); - test(p->first.l == i); - test(p->second.s1.l == i); + Struct1 s1; + s1.l = i; + IndexedStruct1Struct2Map::iterator p = m.findByS1(s1); + test(p != m.end()); + test(p->first.l == i); + test(p->second.s1.l == i); } IceUtil::Time total = _watch.stop(); @@ -571,12 +571,12 @@ TestApp::Struct1Class1MapIndexTest(IndexedStruct1Class1Map& m) _watch.start(); for(int i = 0; i < _repetitions; ++i) { - ostringstream os; - os << i; + ostringstream os; + os << i; - IndexedStruct1Class1Map::iterator p = m.findByS(os.str()); - test(p != m.end()); - test(p->first.l == i); + IndexedStruct1Class1Map::iterator p = m.findByS(os.str()); + test(p != m.end()); + test(p->first.l == i); } IceUtil::Time total = _watch.stop(); IceUtil::Time perRecord = total / _repetitions; @@ -603,25 +603,25 @@ TestApp::Struct1ObjectMapTest() int i; _watch.start(); { - Freeze::TransactionHolder txHolder(_connection); - for(i = 0; i < _repetitions; ++i) - { - s1.l = i; - Ice::ObjectPtr o; - if((i % 2) == 0) - { - o = c2; - } - else - { - o = c1; - } - ostringstream os; - os << i; - c1->s = os.str(); - m.put(Struct1ObjectMap::value_type(s1, o)); - } - txHolder.commit(); + Freeze::TransactionHolder txHolder(_connection); + for(i = 0; i < _repetitions; ++i) + { + s1.l = i; + Ice::ObjectPtr o; + if((i % 2) == 0) + { + o = c2; + } + else + { + o = c1; + } + ostringstream os; + os << i; + c1->s = os.str(); + m.put(Struct1ObjectMap::value_type(s1, o)); + } + txHolder.commit(); } IceUtil::Time total = _watch.stop(); IceUtil::Time perRecord = total / _repetitions; @@ -635,27 +635,27 @@ TestApp::Struct1ObjectMapTest() _watch.start(); for(i = 0; i < _repetitions; ++i) { - s1.l = i; - Struct1ObjectMap::iterator p = m.find(s1); - test(p != m.end()); - Ice::ObjectPtr o = p->second; - Class1Ptr nc1; - if((i % 2) == 0) - { - Class2Ptr nc2 = Class2Ptr::dynamicCast(o); - test(nc2); - - test(nc2->rec == nc2); - nc1 = Class1Ptr::dynamicCast(nc2->obj); - } - else - { - nc1 = Class1Ptr::dynamicCast(o); - } - test(nc1); - ostringstream os; - os << i; - test(nc1->s == os.str()); + s1.l = i; + Struct1ObjectMap::iterator p = m.find(s1); + test(p != m.end()); + Ice::ObjectPtr o = p->second; + Class1Ptr nc1; + if((i % 2) == 0) + { + Class2Ptr nc2 = Class2Ptr::dynamicCast(o); + test(nc2); + + test(nc2->rec == nc2); + nc1 = Class1Ptr::dynamicCast(nc2->obj); + } + else + { + nc1 = Class1Ptr::dynamicCast(o); + } + test(nc1); + ostringstream os; + os << i; + test(nc1->s == os.str()); } total = _watch.stop(); perRecord = total / _repetitions; @@ -668,13 +668,13 @@ TestApp::Struct1ObjectMapTest() // _watch.start(); { - Freeze::TransactionHolder txHolder(_connection); - for(i = 0; i < _repetitions; ++i) - { - s1.l = i; - m.erase(s1); - } - txHolder.commit(); + Freeze::TransactionHolder txHolder(_connection); + for(i = 0; i < _repetitions; ++i) + { + s1.l = i; + m.erase(s1); + } + txHolder.commit(); } total = _watch.stop(); perRecord = total / _repetitions; @@ -690,15 +690,15 @@ public: Ice::ObjectPtr create(const string& type) { - if(type == "::Class1") - { - return new Class1(); - } - else if(type == "::Class2") - { - return new Class2(); - } - return 0; + if(type == "::Class1") + { + return new Class1(); + } + else if(type == "::Class2") + { + return new Class2(); + } + return 0; } void @@ -709,8 +709,8 @@ public: void install(const Ice::CommunicatorPtr& communicator) { - communicator->addObjectFactory(this, "::Class1"); - communicator->addObjectFactory(this, "::Class2"); + communicator->addObjectFactory(this, "::Class1"); + communicator->addObjectFactory(this, "::Class2"); } }; typedef IceUtil::Handle<MyFactory> MyFactoryPtr; @@ -729,8 +729,8 @@ TestApp::run(int argc, char* argv[]) cout << "IntIntMap" << endl; #if defined(_MSC_VER) && (_MSC_VER < 1310) { - IntIntMap* dummy = 0; - IntIntMapTest("IntIntMap", dummy); + IntIntMap* dummy = 0; + IntIntMapTest("IntIntMap", dummy); } #else IntIntMapTest<IntIntMap>("IntIntMap"); @@ -739,8 +739,8 @@ TestApp::run(int argc, char* argv[]) cout << "IntIntMap with index" << endl; #if defined(_MSC_VER) && (_MSC_VER < 1310) { - IndexedIntIntMap* dummy = 0; - IntIntMapTest("IndexedIntIntMap", dummy); + IndexedIntIntMap* dummy = 0; + IntIntMapTest("IndexedIntIntMap", dummy); } #else IntIntMapTest<IndexedIntIntMap>("IndexedIntIntMap"); @@ -749,8 +749,8 @@ TestApp::run(int argc, char* argv[]) cout <<"Struct1Struct2Map" << endl; #if defined(_MSC_VER) && (_MSC_VER < 1310) { - Struct1Struct2Map* dummy = 0; - Struct1Struct2MapTest("Struct1Struct2Map", dummy); + Struct1Struct2Map* dummy = 0; + Struct1Struct2MapTest("Struct1Struct2Map", dummy); } #else Struct1Struct2MapTest<Struct1Struct2Map>("Struct1Struct2Map"); @@ -759,8 +759,8 @@ TestApp::run(int argc, char* argv[]) cout <<"Struct1Struct2Map with index" << endl; #if defined(_MSC_VER) && (_MSC_VER < 1310) { - IndexedStruct1Struct2Map* dummy = 0; - Struct1Struct2MapTest("IndexedStruct1Struct2Map", dummy); + IndexedStruct1Struct2Map* dummy = 0; + Struct1Struct2MapTest("IndexedStruct1Struct2Map", dummy); } #else Struct1Struct2MapTest<IndexedStruct1Struct2Map>("IndexedStruct1Struct2Map"); @@ -769,8 +769,8 @@ TestApp::run(int argc, char* argv[]) cout <<"Struct1Class1Map" << endl; #if defined(_MSC_VER) && (_MSC_VER < 1310) { - Struct1Class1Map* dummy = 0; - Struct1Class1MapTest("Struct1Class1Map", dummy); + Struct1Class1Map* dummy = 0; + Struct1Class1MapTest("Struct1Class1Map", dummy); } #else Struct1Class1MapTest<Struct1Class1Map>("Struct1Class1Map"); @@ -779,8 +779,8 @@ TestApp::run(int argc, char* argv[]) cout <<"Struct1Class1Map with index" << endl; #if defined(_MSC_VER) && (_MSC_VER < 1310) { - IndexedStruct1Class1Map* dummy = 0; - Struct1Class1MapTest("IndexedStruct1Class1Map", dummy); + IndexedStruct1Class1Map* dummy = 0; + Struct1Class1MapTest("IndexedStruct1Class1Map", dummy); } #else Struct1Class1MapTest<IndexedStruct1Class1Map>("IndexedStruct1Class1Map"); @@ -795,8 +795,8 @@ TestApp::run(int argc, char* argv[]) cout <<"IntIntMap (read test)" << endl; #if defined(_MSC_VER) && (_MSC_VER < 1310) { - IntIntMap* dummy = 0; - IntIntMapReadTest("IntIntMap", dummy); + IntIntMap* dummy = 0; + IntIntMapReadTest("IntIntMap", dummy); } #else IntIntMapReadTest<IntIntMap>("IntIntMap"); @@ -805,8 +805,8 @@ TestApp::run(int argc, char* argv[]) cout <<"IntIntMap with index(read test)" << endl; #if defined(_MSC_VER) && (_MSC_VER < 1310) { - IndexedIntIntMap* dummy = 0; - IntIntMapReadTest("IndexedIntIntMap", dummy); + IndexedIntIntMap* dummy = 0; + IntIntMapReadTest("IndexedIntIntMap", dummy); } #else IntIntMapReadTest<IndexedIntIntMap>("IndexedIntIntMap"); diff --git a/cpp/demo/Freeze/library/Client.cpp b/cpp/demo/Freeze/library/Client.cpp index 2cd23ba1bf8..4c13a512683 100644 --- a/cpp/demo/Freeze/library/Client.cpp +++ b/cpp/demo/Freeze/library/Client.cpp @@ -43,15 +43,15 @@ LibraryClient::interruptCallback(int) { try { - communicator()->destroy(); + communicator()->destroy(); } catch(const IceUtil::Exception& ex) { - cerr << appName() << ": " << ex << endl; + cerr << appName() << ": " << ex << endl; } catch(...) { - cerr << appName() << ": unknown exception" << endl; + cerr << appName() << ": unknown exception" << endl; } exit(EXIT_SUCCESS); } diff --git a/cpp/demo/Freeze/library/Collocated.cpp b/cpp/demo/Freeze/library/Collocated.cpp index 5c7ed0261d3..a3457c081dc 100644 --- a/cpp/demo/Freeze/library/Collocated.cpp +++ b/cpp/demo/Freeze/library/Collocated.cpp @@ -19,7 +19,7 @@ class LibraryCollocated : public Ice::Application public: LibraryCollocated(const string& envName) : - _envName(envName) + _envName(envName) { } @@ -61,7 +61,7 @@ LibraryCollocated::run(int argc, char* argv[]) Ice::Int evictorSize = properties->getPropertyAsInt("Library.EvictorSize"); if(evictorSize > 0) { - evictor->setSize(evictorSize); + evictor->setSize(evictorSize); } // @@ -96,15 +96,15 @@ LibraryCollocated::interruptCallback(int) { try { - communicator()->destroy(); + communicator()->destroy(); } catch(const IceUtil::Exception& ex) { - cerr << appName() << ": " << ex << endl; + cerr << appName() << ": " << ex << endl; } catch(...) { - cerr << appName() << ": unknown exception" << endl; + cerr << appName() << ": unknown exception" << endl; } exit(EXIT_SUCCESS); } diff --git a/cpp/demo/Freeze/library/Library.ice b/cpp/demo/Freeze/library/Library.ice index 7111b0f1eac..87663189286 100644 --- a/cpp/demo/Freeze/library/Library.ice +++ b/cpp/demo/Freeze/library/Library.ice @@ -92,7 +92,7 @@ class Book * **/ ["freeze:write"] void destroy() - throws DatabaseException; + throws DatabaseException; /** * @@ -105,7 +105,7 @@ class Book * **/ ["freeze:write"] void rentBook(string name) - throws BookRentedException; + throws BookRentedException; /** * @@ -118,7 +118,7 @@ class Book * **/ ["cpp:const"] idempotent string getRenterName() - throws BookNotRentedException; + throws BookNotRentedException; /** * @@ -129,7 +129,7 @@ class Book * **/ ["freeze:write"] void returnBook() - throws BookNotRentedException; + throws BookNotRentedException; /** * @@ -177,7 +177,7 @@ interface Library * **/ Book* createBook(BookDescription description) - throws DatabaseException, BookExistsException; + throws DatabaseException, BookExistsException; /** * @@ -192,7 +192,7 @@ interface Library * **/ ["cpp:const"] idempotent Book* findByIsbn(string isbn) - throws DatabaseException; + throws DatabaseException; /** * @@ -207,7 +207,7 @@ interface Library * **/ ["cpp:const"] idempotent BookPrxSeq findByAuthors(string authors) - throws DatabaseException; + throws DatabaseException; /** * @@ -220,7 +220,7 @@ interface Library * **/ idempotent void setEvictorSize(int size) - throws DatabaseException; + throws DatabaseException; /** * diff --git a/cpp/demo/Freeze/library/LibraryI.cpp b/cpp/demo/Freeze/library/LibraryI.cpp index 450420c6f55..8a950d3b95c 100644 --- a/cpp/demo/Freeze/library/LibraryI.cpp +++ b/cpp/demo/Freeze/library/LibraryI.cpp @@ -24,19 +24,19 @@ BookI::destroy(const Ice::Current&) IceUtil::Mutex::Lock lock(*this); if(_destroyed) { - throw Ice::ObjectNotExistException(__FILE__, __LINE__); + throw Ice::ObjectNotExistException(__FILE__, __LINE__); } _destroyed = true; try { - _library->remove(description); + _library->remove(description); } catch(const Freeze::DatabaseException& ex) { - DatabaseException e; - e.message = ex.message; - throw e; + DatabaseException e; + e.message = ex.message; + throw e; } } @@ -68,7 +68,7 @@ BookI::getRenterName(const Ice::Current&) const if(rentalCustomerName.empty()) { - throw BookNotRentedException(); + throw BookNotRentedException(); } return rentalCustomerName; } @@ -85,7 +85,7 @@ BookI::rentBook(const string& name, const Ice::Current&) if(!rentalCustomerName.empty()) { - throw BookRentedException(); + throw BookRentedException(); } rentalCustomerName = name; } @@ -102,7 +102,7 @@ BookI::returnBook(const Ice::Current&) if(rentalCustomerName.empty()) { - throw BookNotRentedException(); + throw BookNotRentedException(); } rentalCustomerName.clear();; } @@ -128,14 +128,14 @@ class IsbnToBook public: IsbnToBook(const Ice::ObjectAdapterPtr& adapter) : - _adapter(adapter) + _adapter(adapter) { } BookPrx operator()(const string& isbn) { - return BookPrx::uncheckedCast(_adapter->createProxy(createBookIdentity(isbn))); + return BookPrx::uncheckedCast(_adapter->createProxy(createBookIdentity(isbn))); } private: @@ -144,8 +144,8 @@ private: }; LibraryI::LibraryI(const Ice::CommunicatorPtr& communicator, - const string& envName, const string& dbName, - const Freeze::EvictorPtr& evictor) : + const string& envName, const string& dbName, + const Freeze::EvictorPtr& evictor) : _evictor(evictor), _connection(Freeze::createConnection(communicator, envName)), _authors(_connection, dbName) @@ -163,25 +163,25 @@ LibraryI::createBook(const Demo::BookDescription& description, const Ice::Curren // BookPrx book; { - book = IsbnToBook(c.adapter)(description.isbn); + book = IsbnToBook(c.adapter)(description.isbn); } #else BookPrx book = IsbnToBook(c.adapter)(description.isbn); #endif try { - book->ice_ping(); + book->ice_ping(); - // - // The book already exists. - // - throw BookExistsException(); + // + // The book already exists. + // + throw BookExistsException(); } catch(const Ice::ObjectNotExistException&) { - // - // Book doesn't exist, ignore the exception. - // + // + // Book doesn't exist, ignore the exception. + // } BookPtr bookI = new BookI(this); @@ -205,7 +205,7 @@ LibraryI::createBook(const Demo::BookDescription& description, const Ice::Curren StringIsbnSeqDict::iterator p = _authors.find(description.authors); if(p != _authors.end()) { - isbnSeq = p->second; + isbnSeq = p->second; } isbnSeq.push_back(description.isbn); @@ -224,16 +224,16 @@ LibraryI::findByIsbn(const string& isbn, const Ice::Current& c) const try { - BookPrx book = IsbnToBook(c.adapter)(isbn); - book->ice_ping(); - return book; + BookPrx book = IsbnToBook(c.adapter)(isbn); + book->ice_ping(); + return book; } catch(const Ice::ObjectNotExistException&) { - // - // Book doesn't exist, return a null proxy. - // - return 0; + // + // Book doesn't exist, return a null proxy. + // + return 0; } } @@ -252,8 +252,8 @@ LibraryI::findByAuthors(const string& authors, const Ice::Current& c) const if(p != _authors.end()) { - books.reserve(p->second.size()); - transform(p->second.begin(), p->second.end(), back_inserter(books), IsbnToBook(c.adapter)); + books.reserve(p->second.size()); + transform(p->second.begin(), p->second.end(), back_inserter(books), IsbnToBook(c.adapter)); } return books; @@ -286,43 +286,43 @@ LibraryI::remove(const BookDescription& description) try { - StringIsbnSeqDict::iterator p = _authors.find(description.authors); - - assert(p != _authors.end()); - - // - // Remove the isbn number from the sequence. - // - Ice::StringSeq isbnSeq = p->second; - isbnSeq.erase(remove_if(isbnSeq.begin(), isbnSeq.end(), bind2nd(equal_to<string>(), description.isbn)), - isbnSeq.end()); - - if(isbnSeq.empty()) - { - // - // If there are no further associated isbn numbers then remove - // the record. - // - _authors.erase(p); - } - else - { - // - // Otherwise, write back the new record. - // - p.set(isbnSeq); - } - - // - // This can throw EvictorDeactivatedException (which indicates - // an internal error). The exception is currently ignored. - // - _evictor->remove(createBookIdentity(description.isbn)); + StringIsbnSeqDict::iterator p = _authors.find(description.authors); + + assert(p != _authors.end()); + + // + // Remove the isbn number from the sequence. + // + Ice::StringSeq isbnSeq = p->second; + isbnSeq.erase(remove_if(isbnSeq.begin(), isbnSeq.end(), bind2nd(equal_to<string>(), description.isbn)), + isbnSeq.end()); + + if(isbnSeq.empty()) + { + // + // If there are no further associated isbn numbers then remove + // the record. + // + _authors.erase(p); + } + else + { + // + // Otherwise, write back the new record. + // + p.set(isbnSeq); + } + + // + // This can throw EvictorDeactivatedException (which indicates + // an internal error). The exception is currently ignored. + // + _evictor->remove(createBookIdentity(description.isbn)); } catch(const Freeze::DatabaseException& ex) { - DatabaseException e; - e.message = ex.message; - throw e; + DatabaseException e; + e.message = ex.message; + throw e; } } diff --git a/cpp/demo/Freeze/library/LibraryI.h b/cpp/demo/Freeze/library/LibraryI.h index 6733f6e3f35..aba7775842d 100644 --- a/cpp/demo/Freeze/library/LibraryI.h +++ b/cpp/demo/Freeze/library/LibraryI.h @@ -21,8 +21,8 @@ class LibraryI : public Demo::Library, public IceUtil::Mutex public: LibraryI(const Ice::CommunicatorPtr& communicator, - const std::string& envName, const std::string& dbName, - const Freeze::EvictorPtr& evictor); + const std::string& envName, const std::string& dbName, + const Freeze::EvictorPtr& evictor); virtual Demo::BookPrx createBook(const Demo::BookDescription&, const Ice::Current&); virtual Demo::BookPrx findByIsbn(const std::string&, const Ice::Current&) const; diff --git a/cpp/demo/Freeze/library/Parser.cpp b/cpp/demo/Freeze/library/Parser.cpp index eeb8046327d..c884b42fd6e 100644 --- a/cpp/demo/Freeze/library/Parser.cpp +++ b/cpp/demo/Freeze/library/Parser.cpp @@ -51,37 +51,37 @@ Parser::addBook(const list<string>& _args) { if(_args.size() != 3) { - error("`add' requires at exactly three arguments (type `help' for more info)"); - return; + error("`add' requires at exactly three arguments (type `help' for more info)"); + return; } try { - list<string> args = _args; + list<string> args = _args; - BookDescription desc; - desc.isbn = args.front(); - args.pop_front(); - desc.title = args.front(); - args.pop_front(); - desc.authors = args.front(); + BookDescription desc; + desc.isbn = args.front(); + args.pop_front(); + desc.title = args.front(); + args.pop_front(); + desc.authors = args.front(); - BookPrx book = _library->createBook(desc); - cout << "added new book with isbn " << desc.isbn << endl; + BookPrx book = _library->createBook(desc); + cout << "added new book with isbn " << desc.isbn << endl; } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const BookExistsException&) { - error("the book already exists."); + error("the book already exists."); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -90,36 +90,36 @@ Parser::findIsbn(const list<string>& args) { if(args.size() != 1) { - error("`isbn' requires exactly one argument (type `help' for more info)"); - return; + error("`isbn' requires exactly one argument (type `help' for more info)"); + return; } try { - _foundBooks.clear(); - _current = _foundBooks.begin(); - - BookPrx book = _library->findByIsbn(args.front()); - if(!book) - { - cout << "no book with that ISBN number exists." << endl; - } - else - { - _foundBooks.push_back(book); - _current = _foundBooks.begin(); - printCurrent(); - } + _foundBooks.clear(); + _current = _foundBooks.begin(); + + BookPrx book = _library->findByIsbn(args.front()); + if(!book) + { + cout << "no book with that ISBN number exists." << endl; + } + else + { + _foundBooks.push_back(book); + _current = _foundBooks.begin(); + printCurrent(); + } } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -128,26 +128,26 @@ Parser::findAuthors(const list<string>& args) { if(args.size() != 1) { - error("`authors' requires exactly one argument (type `help' for more info)"); - return; + error("`authors' requires exactly one argument (type `help' for more info)"); + return; } try { - _foundBooks = _library->findByAuthors(args.front()); - _current = _foundBooks.begin(); - cout << "number of books found: " << _foundBooks.size() << endl; - printCurrent(); + _foundBooks = _library->findByAuthors(args.front()); + _current = _foundBooks.begin(); + cout << "number of books found: " << _foundBooks.size() << endl; + printCurrent(); } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -156,7 +156,7 @@ Parser::nextFoundBook() { if(_current != _foundBooks.end()) { - ++_current; + ++_current; } printCurrent(); } @@ -166,31 +166,31 @@ Parser::printCurrent() { try { - if(_current != _foundBooks.end()) - { - BookDescription desc = (*_current)->getBookDescription(); - string renter; - try - { - renter = (*_current)->getRenterName(); - } - catch(const BookNotRentedException&) - { - } - - cout << "current book is:" << endl; - cout << "isbn: " << desc.isbn << endl; - cout << "title: " << desc.title << endl; - cout << "authors: " << desc.authors << endl; - if(!renter.empty()) - { - cout << "rented: " << renter << endl; - } - } - else - { - cout << "no current book" << endl; - } + if(_current != _foundBooks.end()) + { + BookDescription desc = (*_current)->getBookDescription(); + string renter; + try + { + renter = (*_current)->getRenterName(); + } + catch(const BookNotRentedException&) + { + } + + cout << "current book is:" << endl; + cout << "isbn: " << desc.isbn << endl; + cout << "title: " << desc.title << endl; + cout << "authors: " << desc.authors << endl; + if(!renter.empty()) + { + cout << "rented: " << renter << endl; + } + } + else + { + cout << "no current book" << endl; + } } catch(const Ice::ObjectNotExistException&) { @@ -198,9 +198,9 @@ Parser::printCurrent() } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -209,25 +209,25 @@ Parser::rentCurrent(const list<string>& args) { if(args.size() != 1) { - error("`rent' requires exactly one argument (type `help' for more info)"); - return; + error("`rent' requires exactly one argument (type `help' for more info)"); + return; } try { - if(_current != _foundBooks.end()) - { - (*_current)->rentBook(args.front()); - cout << "the book is now rented by `" << args.front() << "'" << endl; - } - else - { - cout << "no current book" << endl; - } + if(_current != _foundBooks.end()) + { + (*_current)->rentBook(args.front()); + cout << "the book is now rented by `" << args.front() << "'" << endl; + } + else + { + cout << "no current book" << endl; + } } catch(const BookRentedException&) { - cout << "the book has already been rented." << endl; + cout << "the book has already been rented." << endl; } catch(const Ice::ObjectNotExistException&) { @@ -235,13 +235,13 @@ Parser::rentCurrent(const list<string>& args) } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -250,19 +250,19 @@ Parser::returnCurrent() { try { - if(_current != _foundBooks.end()) - { - (*_current)->returnBook(); - cout << "the book has been returned." << endl; - } - else - { - cout << "no current book" << endl; - } + if(_current != _foundBooks.end()) + { + (*_current)->returnBook(); + cout << "the book has been returned." << endl; + } + else + { + cout << "no current book" << endl; + } } catch(const BookNotRentedException&) { - cout << "the book is not currently rented." << endl; + cout << "the book is not currently rented." << endl; } catch(const Ice::ObjectNotExistException&) { @@ -270,13 +270,13 @@ Parser::returnCurrent() } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -285,15 +285,15 @@ Parser::removeCurrent() { try { - if(_current != _foundBooks.end()) - { - (*_current)->destroy(); - cout << "removed current book" << endl; - } - else - { - cout << "no current book" << endl; - } + if(_current != _foundBooks.end()) + { + (*_current)->destroy(); + cout << "removed current book" << endl; + } + else + { + cout << "no current book" << endl; + } } catch(const Ice::ObjectNotExistException&) { @@ -301,13 +301,13 @@ Parser::removeCurrent() } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -316,23 +316,23 @@ Parser::setEvictorSize(const list<string>& args) { if(args.size() != 1) { - error("`size' requires exactly one argument (type `help' for more info)"); - return; + error("`size' requires exactly one argument (type `help' for more info)"); + return; } try { - _library->setEvictorSize(atoi(args.front().c_str())); + _library->setEvictorSize(atoi(args.front().c_str())); } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -341,13 +341,13 @@ Parser::shutdown() { try { - _library->shutdown(); + _library->shutdown(); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -356,105 +356,105 @@ Parser::getInput(char* buf, int& result, int maxSize) { if(!_commands.empty()) { - if(_commands == ";") - { - result = 0; - } - else - { + if(_commands == ";") + { + result = 0; + } + else + { #if defined(_MSC_VER) && !defined(_STLP_MSVC) - // COMPILERBUG: Stupid Visual C++ defines min and max as macros - result = _MIN(maxSize, static_cast<int>(_commands.length())); + // COMPILERBUG: Stupid Visual C++ defines min and max as macros + result = _MIN(maxSize, static_cast<int>(_commands.length())); #else - result = min(maxSize, static_cast<int>(_commands.length())); + result = min(maxSize, static_cast<int>(_commands.length())); #endif - strncpy(buf, _commands.c_str(), result); - _commands.erase(0, result); - if(_commands.empty()) - { - _commands = ";"; - } - } + strncpy(buf, _commands.c_str(), result); + _commands.erase(0, result); + if(_commands.empty()) + { + _commands = ";"; + } + } } else if(isatty(fileno(yyin))) { #ifdef HAVE_READLINE const char* prompt = parser->getPrompt(); - char* line = readline(const_cast<char*>(prompt)); - if(!line) - { - result = 0; - } - else - { - if(*line) - { - add_history(line); - } - - result = strlen(line) + 1; - if(result > maxSize) - { - free(line); - error("input line too long"); - result = 0; - } - else - { - strcpy(buf, line); - strcat(buf, "\n"); - free(line); - } - } + char* line = readline(const_cast<char*>(prompt)); + if(!line) + { + result = 0; + } + else + { + if(*line) + { + add_history(line); + } + + result = strlen(line) + 1; + if(result > maxSize) + { + free(line); + error("input line too long"); + result = 0; + } + else + { + strcpy(buf, line); + strcat(buf, "\n"); + free(line); + } + } #else - cout << parser->getPrompt() << flush; - - string line; - while(true) - { - char c = static_cast<char>(getc(yyin)); - if(c == EOF) - { - if(line.size()) - { - line += '\n'; - } - break; - } - - line += c; - - if(c == '\n') - { - break; - } - } - - result = static_cast<int>(line.length()); - if(result > maxSize) - { - error("input line too long"); - buf[0] = EOF; - result = 1; - } - else - { - strcpy(buf, line.c_str()); - } + cout << parser->getPrompt() << flush; + + string line; + while(true) + { + char c = static_cast<char>(getc(yyin)); + if(c == EOF) + { + if(line.size()) + { + line += '\n'; + } + break; + } + + line += c; + + if(c == '\n') + { + break; + } + } + + result = static_cast<int>(line.length()); + if(result > maxSize) + { + error("input line too long"); + buf[0] = EOF; + result = 1; + } + else + { + strcpy(buf, line.c_str()); + } #endif } else { - if(((result = static_cast<int>(fread(buf, 1, maxSize, yyin))) == 0) && ferror(yyin)) - { - error("input in flex scanner failed"); - buf[0] = EOF; - result = 1; - } + if(((result = static_cast<int>(fread(buf, 1, maxSize, yyin))) == 0) && ferror(yyin)) + { + error("input in flex scanner failed"); + buf[0] = EOF; + result = 1; + } } } @@ -477,12 +477,12 @@ Parser::getPrompt() if(_continue) { - _continue = false; - return "(cont) "; + _continue = false; + return "(cont) "; } else { - return ">>> "; + return ">>> "; } } @@ -491,11 +491,11 @@ Parser::error(const char* s) { if(_commands.empty() && !isatty(fileno(yyin))) { - cerr << _currentFile << ':' << _currentLine << ": " << s << endl; + cerr << _currentFile << ':' << _currentLine << ": " << s << endl; } else { - cerr << "error: " << s << endl; + cerr << "error: " << s << endl; } _errors++; } @@ -511,11 +511,11 @@ Parser::warning(const char* s) { if(_commands.empty() && !isatty(fileno(yyin))) { - cerr << _currentFile << ':' << _currentLine << ": warning: " << s << endl; + cerr << _currentFile << ':' << _currentLine << ": warning: " << s << endl; } else { - cerr << "warning: " << s << endl; + cerr << "warning: " << s << endl; } } @@ -550,7 +550,7 @@ Parser::parse(FILE* file, bool debug) int status = yyparse(); if(_errors) { - status = EXIT_FAILURE; + status = EXIT_FAILURE; } parser = 0; @@ -582,7 +582,7 @@ Parser::parse(const string& commands, bool debug) int status = yyparse(); if(_errors) { - status = EXIT_FAILURE; + status = EXIT_FAILURE; } parser = 0; diff --git a/cpp/demo/Freeze/library/RunParser.cpp b/cpp/demo/Freeze/library/RunParser.cpp index 87500d3a6f3..f1a79c08d5f 100644 --- a/cpp/demo/Freeze/library/RunParser.cpp +++ b/cpp/demo/Freeze/library/RunParser.cpp @@ -17,13 +17,13 @@ void usage(const char* appName) { cerr << "Usage: " << appName << " [options] [file...]\n"; - cerr << - "Options:\n" - "-h, --help Show this message.\n" - "-v, --version Display the Ice version.\n" - "-e COMMANDS Execute COMMANDS.\n" - "-d, --debug Print debug messages.\n" - ; + cerr << + "Options:\n" + "-h, --help Show this message.\n" + "-v, --version Display the Ice version.\n" + "-e COMMANDS Execute COMMANDS.\n" + "-d, --debug Print debug messages.\n" + ; } int @@ -35,67 +35,67 @@ runParser(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) int idx = 1; while(idx < argc) { - if(strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0) - { - usage(argv[0]); - return EXIT_SUCCESS; - } - else if(strcmp(argv[idx], "-v") == 0 || strcmp(argv[idx], "--version") == 0) - { - cout << ICE_STRING_VERSION << endl; - return EXIT_SUCCESS; - } - else if(strcmp(argv[idx], "-e") == 0) - { - if(idx + 1 >= argc) + if(strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0) + { + usage(argv[0]); + return EXIT_SUCCESS; + } + else if(strcmp(argv[idx], "-v") == 0 || strcmp(argv[idx], "--version") == 0) + { + cout << ICE_STRING_VERSION << endl; + return EXIT_SUCCESS; + } + else if(strcmp(argv[idx], "-e") == 0) + { + if(idx + 1 >= argc) { - cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl; - usage(argv[0]); - return EXIT_FAILURE; + cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl; + usage(argv[0]); + return EXIT_FAILURE; } - - commands += argv[idx + 1]; - commands += ';'; + + commands += argv[idx + 1]; + commands += ';'; - for(int i = idx ; i + 2 < argc ; ++i) - { - argv[i] = argv[i + 2]; - } - argc -= 2; - } - else if(strcmp(argv[idx], "-d") == 0 || strcmp(argv[idx], "--debug") == 0) - { - debug = true; - for(int i = idx ; i + 1 < argc ; ++i) - { - argv[i] = argv[i + 1]; - } - --argc; - } - else if(argv[idx][0] == '-') - { - cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - else - { - ++idx; - } + for(int i = idx ; i + 2 < argc ; ++i) + { + argv[i] = argv[i + 2]; + } + argc -= 2; + } + else if(strcmp(argv[idx], "-d") == 0 || strcmp(argv[idx], "--debug") == 0) + { + debug = true; + for(int i = idx ; i + 1 < argc ; ++i) + { + argv[i] = argv[i + 1]; + } + --argc; + } + else if(argv[idx][0] == '-') + { + cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl; + usage(argv[0]); + return EXIT_FAILURE; + } + else + { + ++idx; + } } if(argc >= 2 && !commands.empty()) { - cerr << argv[0] << ": `-e' option cannot be used if input files are given" << endl; - usage(argv[0]); - return EXIT_FAILURE; + cerr << argv[0] << ": `-e' option cannot be used if input files are given" << endl; + usage(argv[0]); + return EXIT_FAILURE; } LibraryPrx phoneBook = LibraryPrx::checkedCast(communicator->propertyToProxy("Library.Proxy")); if(!phoneBook) { - cerr << argv[0] << ": invalid proxy" << endl; - return EXIT_FAILURE; + cerr << argv[0] << ": invalid proxy" << endl; + return EXIT_FAILURE; } ParserPtr p = Parser::createParser(phoneBook); @@ -103,43 +103,43 @@ runParser(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) if(argc < 2) // No files given { - if(!commands.empty()) // Commands were given - { - int parseStatus = p->parse(commands, debug); - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } - else // No commands, let's use standard input - { - int parseStatus = p->parse(stdin, debug); - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } + if(!commands.empty()) // Commands were given + { + int parseStatus = p->parse(commands, debug); + if(parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } + } + else // No commands, let's use standard input + { + int parseStatus = p->parse(stdin, debug); + if(parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } + } } else // Process files given on the command line { - for(idx = 1 ; idx < argc ; ++idx) - { - FILE* file = fopen(argv[idx], "r"); - if(file == NULL) - { - cerr << argv[0] << ": can't open file `" << argv[idx] << "': " << strerror(errno) << endl; - return EXIT_FAILURE; - } - - int parseStatus = p->parse(file, debug); + for(idx = 1 ; idx < argc ; ++idx) + { + FILE* file = fopen(argv[idx], "r"); + if(file == NULL) + { + cerr << argv[0] << ": can't open file `" << argv[idx] << "': " << strerror(errno) << endl; + return EXIT_FAILURE; + } + + int parseStatus = p->parse(file, debug); - fclose(file); + fclose(file); - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } + if(parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } + } } return status; diff --git a/cpp/demo/Freeze/library/Server.cpp b/cpp/demo/Freeze/library/Server.cpp index a819e74ee1b..fda90db0811 100644 --- a/cpp/demo/Freeze/library/Server.cpp +++ b/cpp/demo/Freeze/library/Server.cpp @@ -18,7 +18,7 @@ class LibraryServer : public Ice::Application public: LibraryServer(const string& envName) : - _envName(envName) + _envName(envName) { } @@ -53,7 +53,7 @@ LibraryServer::run(int argc, char* argv[]) Ice::Int evictorSize = properties->getPropertyAsInt("Library.EvictorSize"); if(evictorSize > 0) { - evictor->setSize(evictorSize); + evictor->setSize(evictorSize); } // diff --git a/cpp/demo/Freeze/phonebook/Client.cpp b/cpp/demo/Freeze/phonebook/Client.cpp index 5f7c3c032a2..d027ae411a0 100644 --- a/cpp/demo/Freeze/phonebook/Client.cpp +++ b/cpp/demo/Freeze/phonebook/Client.cpp @@ -43,15 +43,15 @@ PhoneBookClient::interruptCallback(int) { try { - communicator()->destroy(); + communicator()->destroy(); } catch(const IceUtil::Exception& ex) { - cerr << appName() << ": " << ex << endl; + cerr << appName() << ": " << ex << endl; } catch(...) { - cerr << appName() << ": unknown exception" << endl; + cerr << appName() << ": unknown exception" << endl; } exit(EXIT_SUCCESS); } diff --git a/cpp/demo/Freeze/phonebook/Collocated.cpp b/cpp/demo/Freeze/phonebook/Collocated.cpp index 6b1efc3c75f..692f33e425e 100644 --- a/cpp/demo/Freeze/phonebook/Collocated.cpp +++ b/cpp/demo/Freeze/phonebook/Collocated.cpp @@ -19,7 +19,7 @@ class PhoneBookCollocated : public Ice::Application public: PhoneBookCollocated(const string& envName) : - _envName(envName) + _envName(envName) { } @@ -82,7 +82,7 @@ PhoneBookCollocated::run(int argc, char* argv[]) Ice::Int evictorSize = properties->getPropertyAsInt("PhoneBook.EvictorSize"); if(evictorSize > 0) { - evictor->setSize(evictorSize); + evictor->setSize(evictorSize); } // @@ -113,15 +113,15 @@ PhoneBookCollocated::interruptCallback(int) { try { - communicator()->destroy(); + communicator()->destroy(); } catch(const IceUtil::Exception& ex) { - cerr << appName() << ": " << ex << endl; + cerr << appName() << ": " << ex << endl; } catch(...) { - cerr << appName() << ": unknown exception" << endl; + cerr << appName() << ": unknown exception" << endl; } exit(EXIT_SUCCESS); } diff --git a/cpp/demo/Freeze/phonebook/Parser.cpp b/cpp/demo/Freeze/phonebook/Parser.cpp index a09f663ceec..a93bab7648d 100644 --- a/cpp/demo/Freeze/phonebook/Parser.cpp +++ b/cpp/demo/Freeze/phonebook/Parser.cpp @@ -52,28 +52,28 @@ Parser::addContacts(const list<string>& args) { if(args.empty()) { - error("`add' requires at least one argument (type `help' for more info)"); - return; + error("`add' requires at least one argument (type `help' for more info)"); + return; } try { - for(list<string>::const_iterator p = args.begin(); p != args.end(); ++p) - { - ContactPrx contact = _phoneBook->createContact(); - contact->setName(*p); - cout << "added new contact for `" << *p << "'" << endl; - } + for(list<string>::const_iterator p = args.begin(); p != args.end(); ++p) + { + ContactPrx contact = _phoneBook->createContact(); + contact->setName(*p); + cout << "added new contact for `" << *p << "'" << endl; + } } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -82,26 +82,26 @@ Parser::findContacts(const list<string>& args) { if(args.size() != 1) { - error("`find' requires exactly one argument (type `help' for more info)"); - return; + error("`find' requires exactly one argument (type `help' for more info)"); + return; } try { - _foundContacts = _phoneBook->findContacts(args.front()); - _current = _foundContacts.begin(); - cout << "number of contacts found: " << _foundContacts.size() << endl; - printCurrent(); + _foundContacts = _phoneBook->findContacts(args.front()); + _current = _foundContacts.begin(); + cout << "number of contacts found: " << _foundContacts.size() << endl; + printCurrent(); } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -110,7 +110,7 @@ Parser::nextFoundContact() { if(_current != _foundContacts.end()) { - ++_current; + ++_current; } printCurrent(); } @@ -120,17 +120,17 @@ Parser::printCurrent() { try { - if(_current != _foundContacts.end()) - { - cout << "current contact is:" << endl; - cout << "name: " << (*_current)->getName() << endl; - cout << "address: " << (*_current)->getAddress() << endl; - cout << "phone: " << (*_current)->getPhone() << endl; - } - else - { - cout << "no current contact" << endl; - } + if(_current != _foundContacts.end()) + { + cout << "current contact is:" << endl; + cout << "name: " << (*_current)->getName() << endl; + cout << "address: " << (*_current)->getAddress() << endl; + cout << "phone: " << (*_current)->getPhone() << endl; + } + else + { + cout << "no current contact" << endl; + } } catch(const Ice::ObjectNotExistException&) { @@ -138,13 +138,13 @@ Parser::printCurrent() } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -153,21 +153,21 @@ Parser::setCurrentName(const list<string>& args) { if(args.size() != 1) { - error("`name' requires exactly one argument (type `help' for more info)"); - return; + error("`name' requires exactly one argument (type `help' for more info)"); + return; } try { - if(_current != _foundContacts.end()) - { - (*_current)->setName(args.front()); - cout << "changed name to `" << args.front() << "'" << endl; - } - else - { - cout << "no current contact" << endl; - } + if(_current != _foundContacts.end()) + { + (*_current)->setName(args.front()); + cout << "changed name to `" << args.front() << "'" << endl; + } + else + { + cout << "no current contact" << endl; + } } catch(const Ice::ObjectNotExistException&) { @@ -175,13 +175,13 @@ Parser::setCurrentName(const list<string>& args) } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -190,21 +190,21 @@ Parser::setCurrentAddress(const list<string>& args) { if(args.size() != 1) { - error("`address' requires exactly one argument (type `help' for more info)"); - return; + error("`address' requires exactly one argument (type `help' for more info)"); + return; } try { - if(_current != _foundContacts.end()) - { - (*_current)->setAddress(args.front()); - cout << "changed address to `" << args.front() << "'" << endl; - } - else - { - cout << "no current contact" << endl; - } + if(_current != _foundContacts.end()) + { + (*_current)->setAddress(args.front()); + cout << "changed address to `" << args.front() << "'" << endl; + } + else + { + cout << "no current contact" << endl; + } } catch(const Ice::ObjectNotExistException&) { @@ -212,13 +212,13 @@ Parser::setCurrentAddress(const list<string>& args) } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -227,21 +227,21 @@ Parser::setCurrentPhone(const list<string>& args) { if(args.size() != 1) { - error("`phone' requires exactly one argument (type `help' for more info)"); - return; + error("`phone' requires exactly one argument (type `help' for more info)"); + return; } try { - if(_current != _foundContacts.end()) - { - (*_current)->setPhone(args.front()); - cout << "changed phone number to `" << args.front() << "'" << endl; - } - else - { - cout << "no current contact" << endl; - } + if(_current != _foundContacts.end()) + { + (*_current)->setPhone(args.front()); + cout << "changed phone number to `" << args.front() << "'" << endl; + } + else + { + cout << "no current contact" << endl; + } } catch(const Ice::ObjectNotExistException&) { @@ -249,13 +249,13 @@ Parser::setCurrentPhone(const list<string>& args) } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -264,15 +264,15 @@ Parser::removeCurrent() { try { - if(_current != _foundContacts.end()) - { - (*_current)->destroy(); - cout << "removed current contact" << endl; - } - else - { - cout << "no current contact" << endl; - } + if(_current != _foundContacts.end()) + { + (*_current)->destroy(); + cout << "removed current contact" << endl; + } + else + { + cout << "no current contact" << endl; + } } catch(const Ice::ObjectNotExistException&) { @@ -280,13 +280,13 @@ Parser::removeCurrent() } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -295,23 +295,23 @@ Parser::setEvictorSize(const list<string>& args) { if(args.size() != 1) { - error("`size' requires exactly one argument (type `help' for more info)"); - return; + error("`size' requires exactly one argument (type `help' for more info)"); + return; } try { - _phoneBook->setEvictorSize(atoi(args.front().c_str())); + _phoneBook->setEvictorSize(atoi(args.front().c_str())); } catch(const DatabaseException& ex) { - error(ex.message); + error(ex.message); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -320,13 +320,13 @@ Parser::shutdown() { try { - _phoneBook->shutdown(); + _phoneBook->shutdown(); } catch(const Ice::Exception& ex) { - ostringstream s; - s << ex; - error(s.str()); + ostringstream s; + s << ex; + error(s.str()); } } @@ -335,105 +335,105 @@ Parser::getInput(char* buf, int& result, int maxSize) { if(!_commands.empty()) { - if(_commands == ";") - { - result = 0; - } - else - { + if(_commands == ";") + { + result = 0; + } + else + { #if defined(_MSC_VER) && !defined(_STLP_MSVC) - // COMPILERBUG: Stupid Visual C++ defines min and max as macros - result = _MIN(maxSize, static_cast<int>(_commands.length())); + // COMPILERBUG: Stupid Visual C++ defines min and max as macros + result = _MIN(maxSize, static_cast<int>(_commands.length())); #else - result = min(maxSize, static_cast<int>(_commands.length())); + result = min(maxSize, static_cast<int>(_commands.length())); #endif - strncpy(buf, _commands.c_str(), result); - _commands.erase(0, result); - if(_commands.empty()) - { - _commands = ";"; - } - } + strncpy(buf, _commands.c_str(), result); + _commands.erase(0, result); + if(_commands.empty()) + { + _commands = ";"; + } + } } else if(isatty(fileno(yyin))) { #ifdef HAVE_READLINE const char* prompt = parser->getPrompt(); - char* line = readline(const_cast<char*>(prompt)); - if(!line) - { - result = 0; - } - else - { - if(*line) - { - add_history(line); - } - - result = strlen(line) + 1; - if(result > maxSize) - { - free(line); - error("input line too long"); - result = 0; - } - else - { - strcpy(buf, line); - strcat(buf, "\n"); - free(line); - } - } + char* line = readline(const_cast<char*>(prompt)); + if(!line) + { + result = 0; + } + else + { + if(*line) + { + add_history(line); + } + + result = strlen(line) + 1; + if(result > maxSize) + { + free(line); + error("input line too long"); + result = 0; + } + else + { + strcpy(buf, line); + strcat(buf, "\n"); + free(line); + } + } #else - cout << parser->getPrompt() << flush; - - string line; - while(true) - { - char c = static_cast<char>(getc(yyin)); - if(c == EOF) - { - if(line.size()) - { - line += '\n'; - } - break; - } - - line += c; - - if(c == '\n') - { - break; - } - } - - result = static_cast<int>(line.length()); - if(result > maxSize) - { - error("input line too long"); - buf[0] = EOF; - result = 1; - } - else - { - strcpy(buf, line.c_str()); - } + cout << parser->getPrompt() << flush; + + string line; + while(true) + { + char c = static_cast<char>(getc(yyin)); + if(c == EOF) + { + if(line.size()) + { + line += '\n'; + } + break; + } + + line += c; + + if(c == '\n') + { + break; + } + } + + result = static_cast<int>(line.length()); + if(result > maxSize) + { + error("input line too long"); + buf[0] = EOF; + result = 1; + } + else + { + strcpy(buf, line.c_str()); + } #endif } else { - if(((result = static_cast<int>(fread(buf, 1, maxSize, yyin))) == 0) && ferror(yyin)) - { - error("input in flex scanner failed"); - buf[0] = EOF; - result = 1; - } + if(((result = static_cast<int>(fread(buf, 1, maxSize, yyin))) == 0) && ferror(yyin)) + { + error("input in flex scanner failed"); + buf[0] = EOF; + result = 1; + } } } @@ -456,12 +456,12 @@ Parser::getPrompt() if(_continue) { - _continue = false; - return "(cont) "; + _continue = false; + return "(cont) "; } else { - return ">>> "; + return ">>> "; } } @@ -470,11 +470,11 @@ Parser::error(const char* s) { if(_commands.empty() && !isatty(fileno(yyin))) { - cerr << _currentFile << ':' << _currentLine << ": " << s << endl; + cerr << _currentFile << ':' << _currentLine << ": " << s << endl; } else { - cerr << "error: " << s << endl; + cerr << "error: " << s << endl; } _errors++; } @@ -490,11 +490,11 @@ Parser::warning(const char* s) { if(_commands.empty() && !isatty(fileno(yyin))) { - cerr << _currentFile << ':' << _currentLine << ": warning: " << s << endl; + cerr << _currentFile << ':' << _currentLine << ": warning: " << s << endl; } else { - cerr << "warning: " << s << endl; + cerr << "warning: " << s << endl; } } @@ -529,7 +529,7 @@ Parser::parse(FILE* file, bool debug) int status = yyparse(); if(_errors) { - status = EXIT_FAILURE; + status = EXIT_FAILURE; } parser = 0; @@ -561,7 +561,7 @@ Parser::parse(const string& commands, bool debug) int status = yyparse(); if(_errors) { - status = EXIT_FAILURE; + status = EXIT_FAILURE; } parser = 0; diff --git a/cpp/demo/Freeze/phonebook/PhoneBookI.cpp b/cpp/demo/Freeze/phonebook/PhoneBookI.cpp index b58fa5adedb..208eac42620 100644 --- a/cpp/demo/Freeze/phonebook/PhoneBookI.cpp +++ b/cpp/demo/Freeze/phonebook/PhoneBookI.cpp @@ -65,18 +65,18 @@ ContactI::destroy(const Ice::Current& c) { try { - _factory->getEvictor()->remove(c.id); + _factory->getEvictor()->remove(c.id); } catch(const Freeze::DatabaseException& ex) { - DatabaseException e; - e.message = ex.message; - throw e; + DatabaseException e; + e.message = ex.message; + throw e; } } PhoneBookI::PhoneBookI(const Freeze::EvictorPtr& evictor, const ContactFactoryPtr& contactFactory, - const NameIndexPtr& index) : + const NameIndexPtr& index) : _evictor(evictor), _contactFactory(contactFactory), _index(index) @@ -88,13 +88,13 @@ class IdentityToContact public: IdentityToContact(const Ice::ObjectAdapterPtr& adapter) : - _adapter(adapter) + _adapter(adapter) { } - ContactPrx operator()(const Ice::Identity& ident) + ContactPrx operator()(const Ice::Identity& ident) { - return ContactPrx::uncheckedCast(_adapter->createProxy(ident)); + return ContactPrx::uncheckedCast(_adapter->createProxy(ident)); } private: @@ -136,19 +136,19 @@ PhoneBookI::findContacts(const string& name, const Ice::Current& c) const { try { - vector<Ice::Identity> identities = _index->find(name); - - Contacts contacts; - contacts.reserve(identities.size()); - transform(identities.begin(), identities.end(), back_inserter(contacts), IdentityToContact(c.adapter)); + vector<Ice::Identity> identities = _index->find(name); + + Contacts contacts; + contacts.reserve(identities.size()); + transform(identities.begin(), identities.end(), back_inserter(contacts), IdentityToContact(c.adapter)); - return contacts; + return contacts; } catch(const Freeze::DatabaseException& ex) { - DatabaseException e; - e.message = ex.message; - throw e; + DatabaseException e; + e.message = ex.message; + throw e; } } diff --git a/cpp/demo/Freeze/phonebook/RunParser.cpp b/cpp/demo/Freeze/phonebook/RunParser.cpp index eac469e60e1..6fce1244c50 100644 --- a/cpp/demo/Freeze/phonebook/RunParser.cpp +++ b/cpp/demo/Freeze/phonebook/RunParser.cpp @@ -17,13 +17,13 @@ void usage(const char* appName) { cerr << "Usage: " << appName << " [options] [file...]\n"; - cerr << - "Options:\n" - "-h, --help Show this message.\n" - "-v, --version Display the Ice version.\n" - "-e COMMANDS Execute COMMANDS.\n" - "-d, --debug Print debug messages.\n" - ; + cerr << + "Options:\n" + "-h, --help Show this message.\n" + "-v, --version Display the Ice version.\n" + "-e COMMANDS Execute COMMANDS.\n" + "-d, --debug Print debug messages.\n" + ; } int @@ -35,67 +35,67 @@ runParser(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) int idx = 1; while(idx < argc) { - if(strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0) - { - usage(argv[0]); - return EXIT_SUCCESS; - } - else if(strcmp(argv[idx], "-v") == 0 || strcmp(argv[idx], "--version") == 0) - { - cout << ICE_STRING_VERSION << endl; - return EXIT_SUCCESS; - } - else if(strcmp(argv[idx], "-e") == 0) - { - if(idx + 1 >= argc) + if(strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0) + { + usage(argv[0]); + return EXIT_SUCCESS; + } + else if(strcmp(argv[idx], "-v") == 0 || strcmp(argv[idx], "--version") == 0) + { + cout << ICE_STRING_VERSION << endl; + return EXIT_SUCCESS; + } + else if(strcmp(argv[idx], "-e") == 0) + { + if(idx + 1 >= argc) { - cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl; - usage(argv[0]); - return EXIT_FAILURE; + cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl; + usage(argv[0]); + return EXIT_FAILURE; } - - commands += argv[idx + 1]; - commands += ';'; + + commands += argv[idx + 1]; + commands += ';'; - for(int i = idx ; i + 2 < argc ; ++i) - { - argv[i] = argv[i + 2]; - } - argc -= 2; - } - else if(strcmp(argv[idx], "-d") == 0 || strcmp(argv[idx], "--debug") == 0) - { - debug = true; - for(int i = idx ; i + 1 < argc ; ++i) - { - argv[i] = argv[i + 1]; - } - --argc; - } - else if(argv[idx][0] == '-') - { - cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl; - usage(argv[0]); - return EXIT_FAILURE; - } - else - { - ++idx; - } + for(int i = idx ; i + 2 < argc ; ++i) + { + argv[i] = argv[i + 2]; + } + argc -= 2; + } + else if(strcmp(argv[idx], "-d") == 0 || strcmp(argv[idx], "--debug") == 0) + { + debug = true; + for(int i = idx ; i + 1 < argc ; ++i) + { + argv[i] = argv[i + 1]; + } + --argc; + } + else if(argv[idx][0] == '-') + { + cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl; + usage(argv[0]); + return EXIT_FAILURE; + } + else + { + ++idx; + } } if(argc >= 2 && !commands.empty()) { - cerr << argv[0] << ": `-e' option cannot be used if input files are given" << endl; - usage(argv[0]); - return EXIT_FAILURE; + cerr << argv[0] << ": `-e' option cannot be used if input files are given" << endl; + usage(argv[0]); + return EXIT_FAILURE; } PhoneBookPrx phoneBook = PhoneBookPrx::checkedCast(communicator->propertyToProxy("PhoneBook.Proxy")); if(!phoneBook) { - cerr << argv[0] << ": invalid proxy" << endl; - return EXIT_FAILURE; + cerr << argv[0] << ": invalid proxy" << endl; + return EXIT_FAILURE; } ParserPtr p = Parser::createParser(phoneBook); @@ -103,43 +103,43 @@ runParser(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) if(argc < 2) // No files given { - if(!commands.empty()) // Commands were given - { - int parseStatus = p->parse(commands, debug); - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } - else // No commands, let's use standard input - { - int parseStatus = p->parse(stdin, debug); - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } + if(!commands.empty()) // Commands were given + { + int parseStatus = p->parse(commands, debug); + if(parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } + } + else // No commands, let's use standard input + { + int parseStatus = p->parse(stdin, debug); + if(parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } + } } else // Process files given on the command line { - for(idx = 1 ; idx < argc ; ++idx) - { - FILE* file = fopen(argv[idx], "r"); - if(file == NULL) - { - cerr << argv[0] << ": can't open file `" << argv[idx] << "': " << strerror(errno) << endl; - return EXIT_FAILURE; - } - - int parseStatus = p->parse(file, debug); + for(idx = 1 ; idx < argc ; ++idx) + { + FILE* file = fopen(argv[idx], "r"); + if(file == NULL) + { + cerr << argv[0] << ": can't open file `" << argv[idx] << "': " << strerror(errno) << endl; + return EXIT_FAILURE; + } + + int parseStatus = p->parse(file, debug); - fclose(file); + fclose(file); - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } + if(parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } + } } return status; diff --git a/cpp/demo/Freeze/phonebook/Server.cpp b/cpp/demo/Freeze/phonebook/Server.cpp index e21d25b485d..13f49990880 100644 --- a/cpp/demo/Freeze/phonebook/Server.cpp +++ b/cpp/demo/Freeze/phonebook/Server.cpp @@ -20,7 +20,7 @@ class PhoneBookServer : public Ice::Application public: PhoneBookServer(const string& envName) : - _envName(envName) + _envName(envName) { } @@ -74,7 +74,7 @@ PhoneBookServer::run(int argc, char* argv[]) Ice::Int evictorSize = properties->getPropertyAsInt("PhoneBook.EvictorSize"); if(evictorSize > 0) { - evictor->setSize(evictorSize); + evictor->setSize(evictorSize); } // |