]> Creatis software - gdcm.git/commitdiff
* Reorder file content
authorregrain <regrain>
Wed, 2 Feb 2005 15:07:41 +0000 (15:07 +0000)
committerregrain <regrain>
Wed, 2 Feb 2005 15:07:41 +0000 (15:07 +0000)
   -- BeNours

12 files changed:
src/gdcmDict.cxx
src/gdcmDict.h
src/gdcmDictEntry.cxx
src/gdcmDictEntry.h
src/gdcmDictSet.cxx
src/gdcmDictSet.h
src/gdcmDirList.cxx
src/gdcmDirList.h
src/gdcmGlobal.cxx
src/gdcmTS.cxx
src/gdcmUtil.cxx
src/gdcmUtil.h

index d867b3da2cf38ece7ec886a5eed9607cffa9f394..5da7a207910360e3032658e94ee22d3254b1e69f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDict.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/01 10:29:55 $
-  Version:   $Revision: 1.71 $
+  Date:      $Date: 2005/02/02 15:07:41 $
+  Version:   $Revision: 1.72 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -89,16 +89,6 @@ Dict::~Dict()
 
 //-----------------------------------------------------------------------------
 // Public
-/**
- * \brief   Remove all Dicom Dictionary Entries
- */
-void Dict::ClearEntry()
-{
-   // we assume all the pointed DictEntries are already cleaned-up
-   // when we clean KeyHt.
-   KeyHt.clear();
-}
-
 /**
  * \brief  adds a new Dicom Dictionary Entry 
  * @param   newEntry entry to add 
@@ -141,7 +131,7 @@ bool Dict::ReplaceEntry(DictEntry const &newEntry)
  * @param   key (group|element)
  * @return  false if Dicom Dictionary Entry doesn't exist
  */
-bool Dict::RemoveEntry (TagKey const &key) 
+bool Dict::RemoveEntry(TagKey const &key) 
 {
    TagKeyHT::const_iterator it = KeyHt.find(key);
    if(it != KeyHt.end()) 
@@ -164,11 +154,21 @@ bool Dict::RemoveEntry (TagKey const &key)
  * @param   elem Dicom element number of the Dicom Element
  * @return  false if Dicom Dictionary Entry doesn't exist
  */
-bool Dict::RemoveEntry (uint16_t group, uint16_t elem)
+bool Dict::RemoveEntry(uint16_t group, uint16_t elem)
 {
    return RemoveEntry(DictEntry::TranslateToKey(group, elem));
 }
 
+/**
+ * \brief   Remove all Dicom Dictionary Entries
+ */
+void Dict::ClearEntry()
+{
+   // we assume all the pointed DictEntries are already cleaned-up
+   // when we clean KeyHt.
+   KeyHt.clear();
+}
+
 /**
  * \brief   Get the dictionary entry identified by a given tag (group,element)
  * @param   group   group of the entry to be found
@@ -207,11 +207,9 @@ DictEntry *Dict::GetNextEntry()
 {
    gdcmAssertMacro (ItKeyHt != KeyHt.end());
 
-   {
-      ++ItKeyHt;
-      if (ItKeyHt != KeyHt.end())
-         return &(ItKeyHt->second);
-   }
+   ++ItKeyHt;
+   if (ItKeyHt != KeyHt.end())
+      return &(ItKeyHt->second);
    return NULL;
 }
 
index 04e80eee97a30e926cb1ac2f289275fd9b609d25..36e579843f1aede15142ecb70ddf0c2b20208a3f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDict.h,v $
   Language:  C++
-  Date:      $Date: 2005/01/31 12:19:33 $
-  Version:   $Revision: 1.36 $
+  Date:      $Date: 2005/02/02 15:07:41 $
+  Version:   $Revision: 1.37 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -56,11 +56,11 @@ public:
    void Print(std::ostream &os = std::cout, std::string const &indent = "");
 
 // Entries
-   void ClearEntry  ();
-   bool AddEntry (DictEntry const &newEntry);
+   bool AddEntry(DictEntry const &newEntry);
    bool ReplaceEntry(DictEntry const &newEntry);
    bool RemoveEntry (TagKey const &key);
    bool RemoveEntry (uint16_t group, uint16_t elem);
+   void ClearEntry();
    
 // Tag
    DictEntry *GetEntry(uint16_t group, uint16_t elem);
index 1d0c7a5a693b29ca2ec762b094793c960f01a761..e8366b249a14629b65a172b1064f0207de5cadad 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDictEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/01 10:29:55 $
-  Version:   $Revision: 1.44 $
+  Date:      $Date: 2005/02/02 15:07:41 $
+  Version:   $Revision: 1.45 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -51,18 +51,6 @@ DictEntry::DictEntry(uint16_t group, uint16_t elem,
 
 //-----------------------------------------------------------------------------
 // Public
-/**
- * \brief   concatenates 2 uint16_t (supposed to be a Dicom group number 
- *                                              and a Dicom element number)
- * @param  group the Dicom group number used to build the tag
- * @param  elem the Dicom element number used to build the tag
- * @return the built tag
- */
-TagKey DictEntry::TranslateToKey(uint16_t group, uint16_t elem)
-{
-   return Util::Format("%04x|%04x", group, elem);
-}
-
 /**
  * \brief       If-and only if-the V(alue) R(epresentation)
  * \            is unset then overwrite it.
@@ -96,6 +84,19 @@ void DictEntry::SetVM(TagName const &vm)
       gdcmErrorMacro( "Overwriting VM might compromise a dictionary");
    }
 }
+
+/**
+ * \brief   concatenates 2 uint16_t (supposed to be a Dicom group number 
+ *                                              and a Dicom element number)
+ * @param  group the Dicom group number used to build the tag
+ * @param  elem the Dicom element number used to build the tag
+ * @return the built tag
+ */
+TagKey DictEntry::TranslateToKey(uint16_t group, uint16_t elem)
+{
+   return Util::Format("%04x|%04x", group, elem);
+}
+
 //-----------------------------------------------------------------------------
 // Protected
 
index 4674479b880e972555090bf38c503d1ff0c046ac..a9129754b38380fc46df9f6b7a2dbcae250aba83 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDictEntry.h,v $
   Language:  C++
-  Date:      $Date: 2005/02/01 13:11:49 $
-  Version:   $Revision: 1.33 $
+  Date:      $Date: 2005/02/02 15:07:41 $
+  Version:   $Revision: 1.34 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -48,9 +48,6 @@ public:
 // Print
    void Print(std::ostream &os = std::cout, std::string const &indent = "");
 
-// Key creation
-   static TagKey TranslateToKey(uint16_t group, uint16_t elem);
-
 // Content of DictEntry
    void SetVR(TagName const &vr);
    void SetVM(TagName const &vm);
@@ -93,6 +90,9 @@ public:
    /// @return the key.
    const TagName &GetKey() const { return Key; }
 
+// Key creation
+   static TagKey TranslateToKey(uint16_t group, uint16_t elem);
+
 private:
    /// \todo FIXME 
    ///        where are the group and elem used except from building up
index 7256c6b1dccaace89f9ea559a9e043b657453d6e..5554a8d02bc19bb5e2fdb2f1616edbfe64f9851e 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDictSet.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/02 10:02:16 $
-  Version:   $Revision: 1.58 $
+  Date:      $Date: 2005/02/02 15:07:41 $
+  Version:   $Revision: 1.59 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -127,6 +127,33 @@ DictEntry *DictSet::NewVirtualDictEntry( uint16_t group,
    return entry;
 }
 
+/**
+ * \brief   Get the first entry while visiting the DictSet
+ * \return  The first Dict if found, otherwhise NULL
+ */
+Dict *DictSet::GetFirstEntry()
+{
+   ItDictHt = Dicts.begin();
+   if( ItDictHt != Dicts.end() )
+      return ItDictHt->second;
+   return NULL;
+}
+
+/**
+ * \brief   Get the next entry while visiting the Hash table (DictSetHT)
+ * \note : meaningfull only if GetFirstEntry already called
+ * \return  The next Dict if found, otherwhise NULL
+ */
+Dict *DictSet::GetNextEntry()
+{
+   gdcmAssertMacro (ItDictHt != Dicts.end());
+  
+   ++ItDictHt;
+   if ( ItDictHt != Dicts.end() )
+      return ItDictHt->second;
+   return NULL;
+}
+
 /**
  * \brief   Obtain from the GDCM_DICT_PATH environnement variable the
  *          path to directory containing the dictionaries. When
@@ -157,33 +184,6 @@ std::string DictSet::BuildDictPath()
    return resultPath;
 }
 
-/**
- * \brief   Get the first entry while visiting the DictSet
- * \return  The first Dict if found, otherwhise NULL
- */
-Dict *DictSet::GetFirstEntry()
-{
-   ItDictHt = Dicts.begin();
-   if( ItDictHt != Dicts.end() )
-      return ItDictHt->second;
-   return NULL;
-}
-
-/**
- * \brief   Get the next entry while visiting the Hash table (DictSetHT)
- * \note : meaningfull only if GetFirstEntry already called
- * \return  The next Dict if found, otherwhise NULL
- */
-Dict *DictSet::GetNextEntry()
-{
-   gdcmAssertMacro (ItDictHt != Dicts.end());
-  
-   ++ItDictHt;
-   if ( ItDictHt != Dicts.end() )
-      return ItDictHt->second;
-   return NULL;
-}
-
 //-----------------------------------------------------------------------------
 // Protected
 /**
index 0d4388a14867f49fdb016acac3489c3e480b68f0..95a3fef53b9fa5982b36ce04e1864ec97a4df580 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDictSet.h,v $
   Language:  C++
-  Date:      $Date: 2005/02/01 13:11:49 $
-  Version:   $Revision: 1.40 $
+  Date:      $Date: 2005/02/02 15:07:41 $
+  Version:   $Revision: 1.41 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -66,11 +66,11 @@ public:
                                   TagName vm     = GDCM_UNKNOWN,
                                   TagName name   = GDCM_UNKNOWN);
 
-   static std::string BuildDictPath();
-
    Dict *GetFirstEntry();
    Dict *GetNextEntry();
 
+   static std::string BuildDictPath();
+
 protected:
    bool AppendDict(Dict *NewDict, DictKey const &name);
 
index 0600fd16a8e686120c1f775a1f32deda94378038..6b95cf8f8b817eddbb63d93fd6e22c3a431df348 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDirList.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/01 10:29:55 $
-  Version:   $Revision: 1.42 $
+  Date:      $Date: 2005/02/02 15:07:41 $
+  Version:   $Revision: 1.43 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -54,14 +54,15 @@ DirList::~DirList()
 
 //-----------------------------------------------------------------------------
 // Public
-/**
- * \brief   Print method
- * @param os ostream to write to 
- */
-void DirList::Print(std::ostream &os)
+bool DirList::IsDirectory(std::string const &dirName)
 {
-   std::copy(Filenames.begin(), Filenames.end(), 
-             std::ostream_iterator<std::string>(os, "\n"));
+#ifndef _MSC_VER
+   struct stat buf;
+   stat(dirName.c_str(), &buf);
+   return S_ISDIR(buf.st_mode);
+#else
+   return (GetFileAttributes(dirName.c_str()) & FILE_ATTRIBUTE_DIRECTORY) != 0;
+#endif
 }
 
 //-----------------------------------------------------------------------------
@@ -149,19 +150,17 @@ int DirList::Explore(std::string const &dirpath, bool recursive)
   return numberOfFiles;
 }
 
-bool DirList::IsDirectory(std::string const &dirName)
-{
-#ifndef _MSC_VER
-   struct stat buf;
-   stat(dirName.c_str(), &buf);
-   return S_ISDIR(buf.st_mode);
-#else
-   return (GetFileAttributes(dirName.c_str()) & FILE_ATTRIBUTE_DIRECTORY) != 0;
-#endif
-}
-
 //-----------------------------------------------------------------------------
 // Print
+/**
+ * \brief   Print method
+ * @param os ostream to write to 
+ */
+void DirList::Print(std::ostream &os)
+{
+   std::copy(Filenames.begin(), Filenames.end(), 
+             std::ostream_iterator<std::string>(os, "\n"));
+}
 
 //-----------------------------------------------------------------------------
 } // end namespace gdcm
index 865c4171994f0150ac3a7b3f428f4b4191790d6c..99ea714acddd68c3a9579472d2a66de3e23bc083 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDirList.h,v $
   Language:  C++
-  Date:      $Date: 2005/02/01 13:11:49 $
-  Version:   $Revision: 1.22 $
+  Date:      $Date: 2005/02/02 15:07:41 $
+  Version:   $Revision: 1.23 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -45,22 +45,21 @@ public :
    DirList(std::string const &dirName, bool recursive=false);
    ~DirList();
 
+   void Print(std::ostream &os = std::cout);
+
    /// Return the name of the directory
    std::string const &GetDirName() const { return DirName; }
 
    /// Return the file names
    DirListType const &GetFilenames() const { return Filenames; };
 
-   /// Print all element of the DirList
-   void Print(std::ostream &os = std::cout);
-
    static bool IsDirectory(std::string const &dirName);
 
 private :
    int Explore(std::string const &dirName, bool recursive=false);
 
+   /// List of file names
    DirListType Filenames;
-
    /// name of the root directory to explore
    std::string DirName;
 };
index 5f455db33ddda99807ab2e6aaffe07ffa473b0fe..6411383e263f1013340426c33d55824ff3a8f6cf 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmGlobal.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/01 10:29:55 $
-  Version:   $Revision: 1.17 $
+  Date:      $Date: 2005/02/02 15:07:41 $
+  Version:   $Revision: 1.18 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -82,6 +82,14 @@ Global::~Global()
 
 //-----------------------------------------------------------------------------
 // Public
+/**
+ * \brief   returns a pointer to Dictionaries Table 
+ */
+DictSet *Global::GetDicts()
+{
+   return Dicts;
+}
+
 /**
  * \brief   returns a pointer to the 'Value Representation Table' 
  */
@@ -89,6 +97,7 @@ VR *Global::GetVR()
 {
    return ValRes;
 }
+
 /**
  * \brief   returns a pointer to the 'Transfer Syntax Table' 
  */
@@ -96,13 +105,7 @@ TS *Global::GetTS()
 {
    return TranSyn;
 }
-/**
- * \brief   returns a pointer to Dictionaries Table 
- */
-DictSet *Global::GetDicts()
-{
-   return Dicts;
-}
+
 /**
  * \brief   returns a pointer to the DicomDir related elements Table 
  */
index fcf4d5b3fa5212adf2d4fa87e9aaf9a2bda9f8bd..b8a3da10795b541e10e880650d5e8c4b3331ba96 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmTS.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/02 10:02:18 $
-  Version:   $Revision: 1.40 $
+  Date:      $Date: 2005/02/02 15:07:41 $
+  Version:   $Revision: 1.41 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -211,6 +211,7 @@ bool TS::IsJPEGLossy(TSKey const &key)
    }
    return r;
 }
+
 /**
  * \brief   Determines if the Transfer Syntax was already encountered
  *          and if it corresponds to a JPEG2000 one
index 4bff2d78961d712800cebfcea4fcb189c5e851b9..485a8a15bebdaec9a9a3b180cbb6a1b534482f47 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmUtil.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/02 10:02:18 $
-  Version:   $Revision: 1.129 $
+  Date:      $Date: 2005/02/02 15:07:41 $
+  Version:   $Revision: 1.130 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -94,6 +94,7 @@ const std::string Util::GDCM_UID = "1.2.826.0.1.3680043.2.1143";
 std::string Util::RootUID        = GDCM_UID;
 
 //-------------------------------------------------------------------------
+// Public
 /**
  * \brief Provide a better 'c++' approach for sprintf
  * For example c code is:
@@ -315,6 +316,48 @@ std::string Util::GetCurrentDateTime()
    return r;
 }
 
+unsigned int Util::GetCurrentThreadID()
+{
+// FIXME the implementation is far from complete
+#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
+  return (unsigned int)GetCurrentThreadId();
+#endif
+#ifdef __linux__
+   return 0;
+   // Doesn't work on fedora, but is in the man page...
+   //return (unsigned int)gettid();
+#endif
+#ifdef __sun
+   return (unsigned int)thr_self();
+#else
+   //default implementation
+   return 0;
+#endif
+}
+
+unsigned int Util::GetCurrentProcessID()
+{
+#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
+  // NOTE: There is also a _getpid()...
+  return (unsigned int)GetCurrentProcessId();
+#else
+  // get process identification, POSIX
+  return (unsigned int)getpid();
+#endif
+}
+
+/**
+ * \brief   tells us if the processor we are working with is BigEndian or not
+ */
+bool Util::IsCurrentProcessorBigEndian()
+{
+#ifdef GDCM_WORDS_BIGENDIAN
+   return true;
+#else
+   return false;
+#endif
+}
+
 /**
  * \brief Create a /DICOM/ string:
  * It should a of even length (no odd length ever)
@@ -371,18 +414,6 @@ bool Util::DicomStringEqual(const std::string &s1, const char *s2)
   return s1_even == s2_even;
 }
 
-/**
- * \brief   tells us if the processor we are working with is BigEndian or not
- */
-bool Util::IsCurrentProcessorBigEndian()
-{
-#ifdef GDCM_WORDS_BIGENDIAN
-   return true;
-#else
-   return false;
-#endif
-}
-
 #ifdef _WIN32
    typedef BOOL(WINAPI * pSnmpExtensionInit) (
            IN DWORD dwTimeZeroReference,
@@ -722,97 +753,6 @@ std::string Util::GetMACAddress()
    }
 }
 
-/**
- * \brief   Return the IP adress of the machine writting the DICOM image
- */
-std::string Util::GetIPAddress()
-{
-   // This is a rip from 
-   // http://www.codeguru.com/Cpp/I-N/internet/network/article.php/c3445/
-#ifndef HOST_NAME_MAX
-   // SUSv2 guarantees that `Host names are limited to 255 bytes'.
-   // POSIX 1003.1-2001 guarantees that `Host names (not including the
-   // terminating NUL) are limited to HOST_NAME_MAX bytes'.
-#define HOST_NAME_MAX 255
-   // In this case we should maybe check the string was not truncated.
-   // But I don't known how to check that...
-#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
-   // with WinSock DLL we need to initialize the WinSock before using gethostname
-   WORD wVersionRequested = MAKEWORD(1,0);
-   WSADATA WSAData;
-   int err = WSAStartup(wVersionRequested,&WSAData);
-   if (err != 0)
-   {
-      // Tell the user that we could not find a usable
-      // WinSock DLL.
-      WSACleanup();
-      return "127.0.0.1";
-   }
-#endif
-  
-#endif //HOST_NAME_MAX
-
-   std::string str;
-   char szHostName[HOST_NAME_MAX+1];
-   int r = gethostname(szHostName, HOST_NAME_MAX);
-   if( r == 0 )
-   {
-      // Get host adresses
-      struct hostent *pHost = gethostbyname(szHostName);
-      for( int i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
-      {
-         for( int j = 0; j<pHost->h_length; j++ )
-         {
-            if( j > 0 ) str += ".";
-            str += Util::Format("%u", 
-                (unsigned int)((unsigned char*)pHost->h_addr_list[i])[j]);
-         }
-         // str now contains one local IP address 
-#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
-   WSACleanup();
-#endif
-
-      }
-   }
-   // If an error occur r == -1
-   // Most of the time it will return 127.0.0.1...
-   return str;
-}
-
-unsigned int Util::GetCurrentThreadID()
-{
-// FIXME the implementation is far from complete
-#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
-  return (unsigned int)GetCurrentThreadId();
-#endif
-#ifdef __linux__
-   return 0;
-   // Doesn't work on fedora, but is in the man page...
-   //return (unsigned int)gettid();
-#endif
-#ifdef __sun
-   return (unsigned int)thr_self();
-#else
-   //default implementation
-   return 0;
-#endif
-}
-
-unsigned int Util::GetCurrentProcessID()
-{
-#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
-  // NOTE: There is also a _getpid()...
-  return (unsigned int)GetCurrentProcessId();
-#else
-  // get process identification, POSIX
-  return (unsigned int)getpid();
-#endif
-}
-
 /**
  * \brief Creates a new UID. As stipulate in the DICOM ref
  *        each time a DICOM image is create it should have 
@@ -933,6 +873,72 @@ std::ostream &binary_write(std::ostream &os, std::string const &val)
    return os.write(val.c_str(), val.size());
 }
 
+//-------------------------------------------------------------------------
+// Protected
+
+//-------------------------------------------------------------------------
+// Private
+/**
+ * \brief   Return the IP adress of the machine writting the DICOM image
+ */
+std::string Util::GetIPAddress()
+{
+   // This is a rip from 
+   // http://www.codeguru.com/Cpp/I-N/internet/network/article.php/c3445/
+#ifndef HOST_NAME_MAX
+   // SUSv2 guarantees that `Host names are limited to 255 bytes'.
+   // POSIX 1003.1-2001 guarantees that `Host names (not including the
+   // terminating NUL) are limited to HOST_NAME_MAX bytes'.
+#define HOST_NAME_MAX 255
+   // In this case we should maybe check the string was not truncated.
+   // But I don't known how to check that...
+#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
+   // with WinSock DLL we need to initialize the WinSock before using gethostname
+   WORD wVersionRequested = MAKEWORD(1,0);
+   WSADATA WSAData;
+   int err = WSAStartup(wVersionRequested,&WSAData);
+   if (err != 0)
+   {
+      // Tell the user that we could not find a usable
+      // WinSock DLL.
+      WSACleanup();
+      return "127.0.0.1";
+   }
+#endif
+  
+#endif //HOST_NAME_MAX
+
+   std::string str;
+   char szHostName[HOST_NAME_MAX+1];
+   int r = gethostname(szHostName, HOST_NAME_MAX);
+   if( r == 0 )
+   {
+      // Get host adresses
+      struct hostent *pHost = gethostbyname(szHostName);
+      for( int i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
+      {
+         for( int j = 0; j<pHost->h_length; j++ )
+         {
+            if( j > 0 ) str += ".";
+            str += Util::Format("%u", 
+                (unsigned int)((unsigned char*)pHost->h_addr_list[i])[j]);
+         }
+         // str now contains one local IP address 
+#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__)
+   WSACleanup();
+#endif
+
+      }
+   }
+   // If an error occur r == -1
+   // Most of the time it will return 127.0.0.1...
+   return str;
+}
+
 //-------------------------------------------------------------------------
 } // end namespace gdcm
 
index 9c53b35905749e176cf6b69a9e9693ed63e4e0bc..f6de2c7dbc3198101ad870bda391340c84950872 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmUtil.h,v $
   Language:  C++
-  Date:      $Date: 2005/02/01 13:11:49 $
-  Version:   $Revision: 1.52 $
+  Date:      $Date: 2005/02/02 15:07:41 $
+  Version:   $Revision: 1.53 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -52,11 +52,11 @@ public:
    static std::string GetCurrentDateTime();
    static unsigned int GetCurrentThreadID();
    static unsigned int GetCurrentProcessID();
+   static bool         IsCurrentProcessorBigEndian();
 
    static std::string DicomString(const char *s, size_t l);
    static std::string DicomString(const char *s);
    static bool        DicomStringEqual(const std::string &s1, const char *s2);
-   static bool        IsCurrentProcessorBigEndian();
 
    static std::string GetMACAddress();
 
@@ -71,12 +71,12 @@ private:
    static const std::string GDCM_UID;
 };
 
-   template <class T> 
-   GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const T &val);
-   GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint16_t &val);
-   GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint32_t &val);
-   GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const char *val);
-   GDCM_EXPORT std::ostream &binary_write(std::ostream &os, std::string const &val);
+template <class T> 
+GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const T &val);
+GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint16_t &val);
+GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const uint32_t &val);
+GDCM_EXPORT std::ostream &binary_write(std::ostream &os, const char *val);
+GDCM_EXPORT std::ostream &binary_write(std::ostream &os, std::string const &val);
 } // end namespace gdcm
 //-----------------------------------------------------------------------------
 #endif