diff options
author | amoghk <amoghk@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2004-03-16 20:00:40 +0000 |
---|---|---|
committer | amoghk <amoghk@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2004-03-16 20:00:40 +0000 |
commit | dd5b1bf7289d48cbaa6bf23bcf63c2b8dc8c19fd (patch) | |
tree | 2677c84836f2bfd7a02642a4bb10b83cabf481ef | |
parent | 348b5a67090d0027d6bacb0afb668a90434183eb (diff) | |
download | ATCD-dd5b1bf7289d48cbaa6bf23bcf63c2b8dc8c19fd.tar.gz |
ChangeLogTag:
-rw-r--r-- | TAO/ChangeLog | 10 | ||||
-rw-r--r-- | TAO/examples/Advanced/ch_12/icp.cpp | 61 | ||||
-rw-r--r-- | TAO/examples/Advanced/ch_12/icp.h | 6 | ||||
-rw-r--r-- | TAO/examples/Advanced/ch_12/server.cpp | 28 | ||||
-rw-r--r-- | TAO/examples/Advanced/ch_12/server.h | 2 | ||||
-rw-r--r-- | TAO/examples/Advanced/ch_18/server.cpp | 39 |
6 files changed, 98 insertions, 48 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog index 47c5b5bf5d6..273e099c12a 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,4 +1,14 @@ +Tue Mar 16 13:51:18 2004 Amogh Kavimandan <amoghk@dre.vanderbilt.edu> + + * examples/Advanced/ch_12/client.cpp + * examples/Advanced/ch_12/server.cpp + * examples/Advanced/ch_12/server.h + * examples/Advanced/ch_12/icp.cpp + * examples/Advanced/ch_12/icp.h + + Added min() function for vc6.0 so that this example compiles. + Tue Mar 16 11:43:28 2004 Amogh Kavimandan <amoghk@dre.vanderbilt.edu> * examples/Advanced/ch_8_and_10/client.cpp diff --git a/TAO/examples/Advanced/ch_12/icp.cpp b/TAO/examples/Advanced/ch_12/icp.cpp index 0f2b6f782ff..d878203a058 100644 --- a/TAO/examples/Advanced/ch_12/icp.cpp +++ b/TAO/examples/Advanced/ch_12/icp.cpp @@ -121,7 +121,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; @@ -131,9 +136,16 @@ 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; + } // Function object. Locates a thermostat that is in the same room as @@ -172,19 +184,32 @@ actual_temp (const StateMap::iterator & pos) { long sum = 0; long count = 0; - StateMap::iterator where = find_if (dstate.begin (), dstate.end (), + 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, dstate.end (), + where = std::find_if (++where, dstate.end (), ThermostatInSameRoom (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 given // id. The attribute is named by the attr parameter. The value is // copied into the buffer pointed to by the value pointer. The len @@ -231,20 +256,20 @@ ICP_get (unsigned long id, if (pos->second.type != thermostat) 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 { @@ -310,10 +335,10 @@ 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); } @@ -350,12 +375,12 @@ ICP_Persist (const char *file) ICP_Persist:: ~ICP_Persist () { - cout<<"~ICP_Persist"<<endl;/////////////////////// + std::cout<<"~ICP_Persist"<<std::endl;/////////////////////// // Open input file, truncating it. ofstream db (m_filename.c_str ()); if (!db) { - cerr << "Error opening " << m_filename << endl; + std::cerr << "Error opening " << m_filename << std::endl; exit (1); } @@ -363,22 +388,22 @@ ICP_Persist:: 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); } db.close (); if (!db) { - cerr << "Error closing " << m_filename << endl; + std::cerr << "Error closing " << m_filename << std::endl; exit (1); } } diff --git a/TAO/examples/Advanced/ch_12/icp.h b/TAO/examples/Advanced/ch_12/icp.h index a824fee3503..bbcc0b84f08 100644 --- a/TAO/examples/Advanced/ch_12/icp.h +++ b/TAO/examples/Advanced/ch_12/icp.h @@ -38,4 +38,10 @@ extern "C" const void *value); } +#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_12/server.cpp b/TAO/examples/Advanced/ch_12/server.cpp index 79fd9a63adb..4b745c72953 100644 --- a/TAO/examples/Advanced/ch_12/server.cpp +++ b/TAO/examples/Advanced/ch_12/server.cpp @@ -19,12 +19,12 @@ // // ============================================================================ +#include <iostream> +#include <fstream> +#include <strstream> #include "server.h" #include <algorithm> #include "icp.h" -#include <strstream> -#include <fstream> -#include <iostream> // The following headers are #included automatically by ACE+TAO. // Therefore, they don't need to be included explicitly. @@ -32,7 +32,7 @@ // #include <iostream.h> const char *Controller_oid = "Controller"; - +const unsigned int DeviceLocator_impl::MAX_EQ_SIZE = 100; // Generic ostream inserter for exceptions. Inserts the exception // name, if available, and the repository ID otherwise. @@ -314,10 +314,10 @@ Controller_impl (PortableServer::POA_ptr poa, : 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; @@ -339,20 +339,20 @@ 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); } AssetMap::iterator i; for (i = m_assets.begin (); i != m_assets.end (); i++) { - afile << i->first << endl; + afile << i->first << std::endl; if (!afile) { - cerr << "Cannot update " << m_asset_file.in () << endl; + std::cerr << "Cannot update " << m_asset_file.in () << std::endl; assert (0); } delete i->second; @@ -360,7 +360,7 @@ Controller_impl:: afile.close (); if (!afile) { - cerr << "Cannot close " << m_asset_file.in () << endl; + std::cerr << "Cannot close " << m_asset_file.in () << std::endl; assert (0); } } @@ -687,7 +687,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; + cout << str.in () << std::endl << std::endl; // Instantiate the servant locator for devices. PortableServer::ServantManager_var locator = @@ -704,7 +704,9 @@ main (int argc, char * argv[]) } 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_12/server.h b/TAO/examples/Advanced/ch_12/server.h index b6ff096c046..a68cfacd9ec 100644 --- a/TAO/examples/Advanced/ch_12/server.h +++ b/TAO/examples/Advanced/ch_12/server.h @@ -211,7 +211,7 @@ private: typedef map<CCS::AssetType, EvictorQueue::iterator> ActiveObjectMap; - static const unsigned int MAX_EQ_SIZE = 100; + static const unsigned int MAX_EQ_SIZE;// = 100; EvictorQueue m_eq; ActiveObjectMap m_aom; diff --git a/TAO/examples/Advanced/ch_18/server.cpp b/TAO/examples/Advanced/ch_18/server.cpp index e4388393b20..5b8d094b4d3 100644 --- a/TAO/examples/Advanced/ch_18/server.cpp +++ b/TAO/examples/Advanced/ch_18/server.cpp @@ -19,15 +19,16 @@ // // ============================================================================ +#include <iostream> +#include <fstream> +#include <strstream> #include "server.h" #include <algorithm> #include "icp.h" #include "orbsvcs/orbsvcs/CosNamingC.h" -#include <strstream> -#include <iostream> -#include <fstream> const char * Controller_oid = "Controller"; +const unsigned int DeviceLocator_impl::MAX_EQ_SIZE = 100; //---------------------------------------------------------------- @@ -43,8 +44,10 @@ resolve_init (CORBA::ORB_ptr orb, const char * id) throw; } catch (const CORBA::Exception & e) { - cerr << "Cannot get initial reference for " - << id << ": " << e << endl; + std::cerr << "Cannot get initial reference for " + << id << ": " + //<< e + << std::endl; throw 0; } assert (!CORBA::is_nil (obj.in ())); @@ -54,13 +57,15 @@ resolve_init (CORBA::ORB_ptr orb, const char * id) ref = T::_narrow (obj.in ()); } catch (const CORBA::Exception & e) { - cerr << "Cannot narrow reference for " - << id << ": " << e << endl; + std::cerr << "Cannot narrow reference for " + << id << ": " + //<< e + << std::endl; throw 0; } if (CORBA::is_nil (ref.in ())) { - cerr << "Incorrect type of reference for " - << id << endl; + std::cerr << "Incorrect type of reference for " + << id << std::endl; throw 0; } return ref._retn (); @@ -365,9 +370,9 @@ Controller_impl ( ) 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; @@ -387,16 +392,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); } AssetMap::iterator i; for (i = m_assets.begin (); i != m_assets.end (); i++) { - afile << i->first << endl; + afile << i->first << std::endl; if (!afile) { - cerr << "Cannot update " << m_asset_file.in () << endl; + std::cerr << "Cannot update " << m_asset_file.in () << std::endl; assert (0); } delete i->second; @@ -777,7 +782,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 (...) { |