From 397081858a897ed5ddc152442a44fda94e12f546 Mon Sep 17 00:00:00 2001 From: amoghk Date: Tue, 16 Mar 2004 20:03:46 +0000 Subject: ChangeLogTag: --- TAO/examples/Advanced/ch_21/client.cpp | 120 +++++++++++++++++---------------- TAO/examples/Advanced/ch_21/icp.cpp | 59 +++++++++++----- TAO/examples/Advanced/ch_21/icp.h | 6 ++ TAO/examples/Advanced/ch_21/server.cpp | 28 ++++---- TAO/examples/Advanced/ch_21/server.h | 2 +- 5 files changed, 126 insertions(+), 89 deletions(-) (limited to 'TAO/examples') diff --git a/TAO/examples/Advanced/ch_21/client.cpp b/TAO/examples/Advanced/ch_21/client.cpp index 5197d130f28..8db73588d82 100644 --- a/TAO/examples/Advanced/ch_21/client.cpp +++ b/TAO/examples/Advanced/ch_21/client.cpp @@ -52,31 +52,31 @@ operator<<(ostream & os, const CORBA::Exception & e) // Show the details for a thermometer or thermostat. -static ostream & -operator<<(ostream &os, CCS::Thermometer_ptr t) +static std::ostream & +operator<<(std::ostream &os, CCS::Thermometer_ptr t) { // Check for nil. if (CORBA::is_nil(t)) { - os << "Cannot show state for nil reference." << endl; + os << "Cannot show state for nil reference." << std::endl; return os; } // Try to narrow and print what kind of device it is. CCS::Thermostat_var tmstat = CCS::Thermostat::_narrow(t); os << (CORBA::is_nil(tmstat.in()) ? "Thermometer:" : "Thermostat:") - << endl; + << std::endl; // Show attribute values. CCS::ModelType_var model = t->model(); CCS::LocType_var location = t->location(); - os << "\tAsset number: " << t->asset_num() << endl; - os << "\tModel : " << model.in() << endl; - os << "\tLocation : " << location.in() << endl; - os << "\tTemperature : " << t->temperature() << endl; + os << "\tAsset number: " << t->asset_num() << std::endl; + os << "\tModel : " << model.in() << std::endl; + os << "\tLocation : " << location.in() << std::endl; + os << "\tTemperature : " << t->temperature() << std::endl; // If device is a thermostat, show nominal temperature. if (!CORBA::is_nil(tmstat.in())) - os << "\tNominal temp: " << tmstat->get_nominal() << endl; + os << "\tNominal temp: " << tmstat->get_nominal() << std::endl; return os; } @@ -84,14 +84,14 @@ operator<<(ostream &os, CCS::Thermometer_ptr t) // Show the information in a BtData struct. -static ostream & -operator<<(ostream &os, const CCS::Thermostat::BtData &btd) +static std::ostream & +operator<<(std::ostream &os, const CCS::Thermostat::BtData &btd) { - os << "CCS::Thermostat::BtData details:" << endl; - os << "\trequested : " << btd.requested << endl; - os << "\tmin_permitted: " << btd.min_permitted << endl; - os << "\tmax_permitted: " << btd.max_permitted << endl; - os << "\terror_msg : " << btd.error_msg << endl; + os << "CCS::Thermostat::BtData details:" << std::endl; + os << "\trequested : " << btd.requested << std::endl; + os << "\tmin_permitted: " << btd.min_permitted << std::endl; + os << "\tmax_permitted: " << btd.max_permitted << std::endl; + os << "\terror_msg : " << btd.error_msg << std::endl; return os; } @@ -100,13 +100,13 @@ operator<<(ostream &os, const CCS::Thermostat::BtData &btd) // Loop over the sequence of records in an EChange exception and // show the details of each record. -static ostream & -operator<<(ostream &os, const CCS::Controller::EChange &ec) +static std::ostream & +operator<<(std::ostream &os, const CCS::Controller::EChange &ec) { for (CORBA::ULong i = 0; i < ec.errors.length(); i++) { - os << "Change failed:" << endl; + os << "Change failed:" << std::endl; os << ec.errors[i].tmstat_ref.in(); // Overloaded << - os << ec.errors[i].info << endl; // Overloaded << + os << ec.errors[i].info << std::endl; // Overloaded << } return os; } @@ -123,16 +123,16 @@ set_temp(CCS::Thermostat_ptr tmstat, CCS::TempType new_temp) CCS::AssetType anum = tmstat->asset_num(); try { - cout << "Setting thermostat " << anum - << " to " << new_temp << " degrees." << endl; + std::cout << "Setting thermostat " << anum + << " to " << new_temp << " degrees." << std::endl; CCS::TempType old_nominal = tmstat->set_nominal(new_temp); - cout << "Old nominal temperature was: " - << old_nominal << endl; - cout << "New nominal temperature is: " - << tmstat->get_nominal() << endl; + std::cout << "Old nominal temperature was: " + << old_nominal << std::endl; + std::cout << "New nominal temperature is: " + << tmstat->get_nominal() << std::endl; } catch (const CCS::Thermostat::BadTemp &bt) { - cerr << "Setting of nominal temperature failed." << endl; - cerr << bt.details << endl; // Overloaded << + std::cerr << "Setting of nominal temperature failed." << std::endl; + std::cerr << bt.details << std::endl; // Overloaded << } } @@ -141,13 +141,14 @@ set_temp(CCS::Thermostat_ptr tmstat, CCS::TempType new_temp) int main(int argc, char * argv[]) { + CORBA::ULong i = 0; try { // Initialize the ORB CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); // Check arguments if (argc != 2) { - cerr << "Usage: client IOR_string" << endl; + std::cerr << "Usage: client IOR_string" << std::endl; throw 0; } @@ -155,7 +156,7 @@ main(int argc, char * argv[]) // and convert to object. CORBA::Object_var obj = orb->string_to_object(argv[1]); if (CORBA::is_nil(obj.in())) { - cerr << "Nil controller reference" << endl; + std::cerr << "Nil controller reference" << std::endl; throw 0; } @@ -164,12 +165,13 @@ main(int argc, char * argv[]) try { ctrl = CCS::Controller::_narrow(obj.in()); } catch (const CORBA::SystemException &se) { - cerr << "Cannot narrow controller reference: " - << se << endl; + std::cerr << "Cannot narrow controller reference: " + //<< se + << std::endl; throw 0; } if (CORBA::is_nil(ctrl.in())) { - cerr << "Wrong type for controller ref." << endl; + std::cerr << "Wrong type for controller ref." << std::endl; throw 0; } @@ -178,10 +180,10 @@ main(int argc, char * argv[]) // Show number of devices. CORBA::ULong len = list->length(); - cout << "Controller has " << len << " device"; + std::cout << "Controller has " << len << " device"; if (len != 1) - cout << "s"; - cout << "." << endl; + std::cout << "s"; + std::cout << "." << std::endl; CCS::Thermometer_var t = ctrl->create_thermometer(27, "Room 1"); CCS::Thermostat_var ts = ctrl->create_thermostat(28, "Room 2", 48); @@ -189,30 +191,30 @@ main(int argc, char * argv[]) CCS::Thermostat_var ts3 = ctrl->create_thermostat(32, "Room 3", 68); CCS::Thermostat_var ts4 = ctrl->create_thermostat(34, "Room 3", 68); CCS::Thermostat_var ts5 = ctrl->create_thermostat(36, "Room 3", 48); - cout << t->location() << endl; - cout << ts->location() << endl; - cout << ts2->location() << endl; + std::cout << t->location() << std::endl; + std::cout << ts->location() << std::endl; + std::cout << ts2->location() << std::endl; t->remove(); list = ctrl->list(); // Show details for each device. - for (CORBA::ULong i = 0; i < list->length(); i++) - cout << list[i]; - cout << endl; + for ( i = 0; i < list->length(); i++) + std::cout << list[i]; + std::cout << std::endl; // Change the location of first device in the list CCS::AssetType anum = list[0U]->asset_num(); - cout << "Changing location of device " - << anum << "." << endl; + std::cout << "Changing location of device " + << anum << "." << std::endl; list[0U]->location("Earth"); // Check that the location was updated - cout << "New details for device " - << anum << " are:" << endl; - cout << list[0U] << endl; + std::cout << "New details for device " + << anum << " are:" << std::endl; + std::cout << list[0U] << std::endl; // Find first thermostat in list. CCS::Thermostat_var tmstat; - for ( CORBA::ULong i = 0; + for ( i = 0; i < list->length() && CORBA::is_nil(tmstat.in()); i++) { tmstat = CCS::Thermostat::_narrow(list[i]); @@ -220,12 +222,12 @@ main(int argc, char * argv[]) // Check that we found a thermostat on the list. if (CORBA::is_nil(tmstat.in())) { - cout << "No thermostat devices in list." << endl; + std::cout << "No thermostat devices in list." << std::endl; } else { // Set temperature of thermostat to // 50 degrees (should work). set_temp(tmstat.inout(), 50); - cout << endl; + std::cout << std::endl; // Set temperature of thermostat to // -10 degrees (should fail). @@ -235,7 +237,7 @@ main(int argc, char * argv[]) // Look for device in Rooms Earth and HAL. This must // locate at least one device because we earlier changed // the location of the first device to Room Earth. - cout << "Looking for devices in Earth and HAL." << endl; + std::cout << "Looking for devices in Earth and HAL." << std::endl; CCS::Controller::SearchSeq ss; ss.length(2); ss[0].key.loc(CORBA::string_dup("Earth")); @@ -243,16 +245,16 @@ main(int argc, char * argv[]) ctrl->find(ss); // Show the devices found in that room. - for (CORBA::ULong i = 0; i < ss.length(); i++) - cout << ss[i].device.in(); // Overloaded << - cout << endl; + for ( i = 0; i < ss.length(); i++) + std::cout << ss[i].device.in(); // Overloaded << + std::cout << std::endl; // Increase the temperature of all thermostats // by 40 degrees. First, make a new list (tss) // containing only thermostats. - cout << "Increasing thermostats by 40 degrees." << endl; + std::cout << "Increasing thermostats by 40 degrees." << std::endl; CCS::Controller::ThermostatSeq tss; - for (CORBA::ULong i = 0; i < list->length(); i++) { + for ( i = 0; i < list->length(); i++) { tmstat = CCS::Thermostat::_narrow(list[i]); if (CORBA::is_nil(tmstat.in())) continue; // Skip thermometers @@ -265,10 +267,12 @@ main(int argc, char * argv[]) try { ctrl->change(tss, 40); } catch (const CCS::Controller::EChange &ec) { - cerr << ec; // Overloaded << + std::cerr << ec; // Overloaded << } } catch (const CORBA::Exception & e) { - cerr << "Uncaught CORBA exception: " << e << endl; + std::cerr << "Uncaught CORBA exception: " + //<< e + << std::endl; return 1; } catch (...) { return 1; diff --git a/TAO/examples/Advanced/ch_21/icp.cpp b/TAO/examples/Advanced/ch_21/icp.cpp index 29b582ec418..3ac9cfb0c82 100644 --- a/TAO/examples/Advanced/ch_21/icp.cpp +++ b/TAO/examples/Advanced/ch_21/icp.cpp @@ -126,7 +126,12 @@ static short vary_temp(short temp) { - long r = lrand48() % 50; + #if defined (__BORLANDC__) || defined (_MSC_VER) + long r = rand() % 50; + #else + long r = lrand48() % 50; + #endif + long delta; if (r < 5) delta = 3; @@ -136,9 +141,15 @@ vary_temp(short temp) delta = 1; else delta = 0; - if (lrand48() % 2) + #if defined (__BORLANDC__) || defined (_MSC_VER) + if (rand() % 2) + #else + if (lrand48() % 2) + #endif + delta = -delta; return temp + delta; + } //---------------------------------------------------------------- @@ -186,14 +197,14 @@ actual_temp(const StateMap::iterator & pos) { long sum = 0; long count = 0; - StateMap::iterator where = find_if( + StateMap::iterator where = std::find_if( dstate.begin(), dstate.end(), ThermostatInSameRoom(pos) ); while (where != dstate.end()) { count++; sum += where->second.nominal_temp; - where = find_if( + where = std::find_if( ++where, dstate.end(), ThermostatInSameRoom(pos) ); @@ -201,6 +212,20 @@ actual_temp(const StateMap::iterator & pos) return vary_temp(count == 0 ? DFLT_TEMP : sum / count); } +//--------------------------------------------------------------- + + +#if (_MSC_VER >= 1200) && (_MSC_VER < 1300) +namespace std +{ + size_t min (const size_t len1, const size_t len2) + { + return ( len1 < len2 ? len1:len2 ); + } +} +#endif/*_MSC_VER*/ + + //---------------------------------------------------------------- // ICP_get() returns an attribute value of the device with the @@ -247,15 +272,15 @@ ICP_get( return -1; // Must be thermostat memcpy( value, &pos->second.nominal_temp, - min(len, sizeof(pos->second.nominal_temp)) + std::min(len, sizeof(pos->second.nominal_temp)) ); } else if (strcmp(attr, "temperature") == 0) { short temp = actual_temp(pos); - memcpy(value, &temp, min(len, sizeof(temp))); + memcpy(value, &temp, std::min(len, sizeof(temp))); } else if (strcmp(attr, "MIN_TEMP") == 0) { - memcpy(value, &MIN_TEMP, min(len, sizeof(MIN_TEMP))); + memcpy(value, &MIN_TEMP, std::min(len, sizeof(MIN_TEMP))); } else if (strcmp(attr, "MAX_TEMP") == 0) { - memcpy(value, &MAX_TEMP, min(len, sizeof(MAX_TEMP))); + memcpy(value, &MAX_TEMP, std::min(len, sizeof(MAX_TEMP))); } else { return -1; // No such attribute } @@ -319,9 +344,9 @@ ICP_Persist:: ICP_Persist(const char * file) : m_filename(file) { // Open input file, creating it if necessary. - fstream db(m_filename.c_str(), ios::in|ios::out, 0666); + std::ifstream db(m_filename.c_str(), std::ios::in|std::ios::out);//, 0666); if (!db) { - cerr << "Error opening " << m_filename << endl; + std::cerr << "Error opening " << m_filename << std::endl; exit(1); } @@ -358,23 +383,23 @@ ICP_Persist:: ~ICP_Persist() { // Open input file, truncating it. - ofstream db(m_filename.c_str()); + std::ofstream db(m_filename.c_str()); if (!db) { - cerr << "Error opening " << m_filename << endl; + std::cerr << "Error opening " << m_filename << std::endl; exit(1); } // Write the state details for each device. StateMap::iterator i; for (i = dstate.begin(); i != dstate.end(); i++) { - db << i->first << endl; - db << (unsigned long)(i->second.type) << endl; - db << i->second.location << endl; + db << i->first << std::endl; + db << (unsigned long)(i->second.type) << std::endl; + db << i->second.location << std::endl; if (i->second.type == thermostat) - db << i->second.nominal_temp << endl; + db << i->second.nominal_temp << std::endl; } if (!db) { - cerr << "Error writing " << m_filename << endl; + std::cerr << "Error writing " << m_filename << std::endl; exit(1); } diff --git a/TAO/examples/Advanced/ch_21/icp.h b/TAO/examples/Advanced/ch_21/icp.h index 3579e7e6d61..ee271ca213f 100644 --- a/TAO/examples/Advanced/ch_21/icp.h +++ b/TAO/examples/Advanced/ch_21/icp.h @@ -40,6 +40,12 @@ extern "C" { ); } +#if defined(_MSC_VAR) && (_MSC_VAR >= 1200) +#pragma warning(pop) +#endif/*_MSC_VAR*/ + +size_t min(const size_t len1, const size_t len2); + #endif /* _ICP_H */ diff --git a/TAO/examples/Advanced/ch_21/server.cpp b/TAO/examples/Advanced/ch_21/server.cpp index 6aa8d0aef2e..02631e1f536 100644 --- a/TAO/examples/Advanced/ch_21/server.cpp +++ b/TAO/examples/Advanced/ch_21/server.cpp @@ -18,18 +18,18 @@ // // ============================================================================ +#include +#include +#include #include "server.h" +#include #include #include "icp.h" -#include -#include -#include -#include using namespace std; const char* Controller_oid = "Controller"; - +const unsigned int DeviceLocator_impl::MAX_EQ_SIZE = 100; //---------------------------------------------------------------- // Generic ostream inserter for exceptions. Inserts the exception @@ -346,9 +346,9 @@ Controller_impl (PortableServer::POA_ptr poa, const char * asset_file) throw (int) : m_poa (PortableServer::POA::_duplicate (poa)), m_asset_file (asset_file) { - fstream afile (m_asset_file.in (), ios::in|ios::out, 0666); + std::ifstream afile (m_asset_file.in (), std::ios::in|std::ios::out);//, 0666); if (!afile) { - cerr << "Cannot open " << m_asset_file.in () << endl; + std::cerr << "Cannot open " << m_asset_file.in () << std::endl; throw 0; } CCS::AssetType anum; @@ -368,16 +368,16 @@ Controller_impl:: { // Write out the current set of asset numbers // and clean up all servant instances. - ofstream afile (m_asset_file.in ()); + std::ofstream afile (m_asset_file.in ()); if (!afile) { - cerr << "Cannot open " << m_asset_file.in () << endl; + std::cerr << "Cannot open " << m_asset_file.in () << std::endl; assert (0); } AssetSet::iterator i; for (i = m_assets.begin (); i != m_assets.end (); i++) { - afile << *i << endl; + afile << *i << std::endl; if (!afile) { - cerr << "Cannot update " << m_asset_file.in () << endl; + std::cerr << "Cannot update " << m_asset_file.in () << std::endl; assert (0); } } @@ -741,7 +741,7 @@ main (int argc, char **argv) // Write a reference for the controller to stdout. CORBA::String_var str = orb->object_to_string (obj.in ()); - cout << str.in () << endl << endl; + std::cout << str.in () << std::endl << std::endl; // Instantiate the servant locator for devices. PortableServer::ServantManager_var locator = @@ -757,7 +757,9 @@ main (int argc, char **argv) orb->run (); } catch (const CORBA::Exception & e) { - cerr << "Uncaught CORBA exception: " << e << endl; + std::cerr << "Uncaught CORBA exception: " + //<< e + << std::endl; return 1; } catch (...) { diff --git a/TAO/examples/Advanced/ch_21/server.h b/TAO/examples/Advanced/ch_21/server.h index bc14156127c..af04760ecd5 100644 --- a/TAO/examples/Advanced/ch_21/server.h +++ b/TAO/examples/Advanced/ch_21/server.h @@ -234,7 +234,7 @@ private: typedef map ActiveObjectMap; - static const unsigned int MAX_EQ_SIZE = 100; + static const unsigned int MAX_EQ_SIZE;// = 100; EvictorQueue m_eq; ActiveObjectMap m_aom; -- cgit v1.2.1