home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 8.img / CLASSINC.ZIP / LTIME.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-04  |  11.2 KB  |  485 lines

  1. #ifndef __LTIME_H
  2. #define __LTIME_H
  3.  
  4. //
  5. // This file contains proprietary information of Borland International.
  6. // Copying or reproduction without prior written approval is prohibited.
  7. //
  8. // Copyright (c) 1990
  9. // Borland International
  10. // 1800 Scotts Valley Dr.
  11. // Scotts Valley, CA 95066
  12. // (408) 438-8400
  13. //
  14.  
  15. // Contents ----------------------------------------------------------------
  16. //
  17. //         BaseTime
  18. //         BaseTime::BaseTime                        default constructor
  19. //         BaseTime::BaseTime                        copy constructor
  20. //         BaseTime::BaseTime                        constructor
  21. //         BaseTime::hour
  22. //         BaseTime::minute
  23. //         BaseTime::second
  24. //         BaseTime::hundreths
  25. //
  26. //         BaseTime::setHour
  27. //         BaseTime::setMinute
  28. //         BaseTime::setSecond
  29. //         BaseTime::setHundreths
  30. //
  31. //         Time
  32. //         Time::Time                                default constructor
  33. //         Time::Time                                copy constructor
  34. //         Time::Time                                constructor
  35. //
  36. // Description
  37. //
  38. //      Provides the class BaseTime as an abstract base class for
  39. //      storing and formatting times.
  40. //      times.
  41. //
  42. //      Provides the Time class for storing times and converting them
  43. //      to ASCII strings of the form "1:23:45.67 pm"
  44. //
  45. // End ---------------------------------------------------------------------
  46.  
  47. // Interface Dependencies ---------------------------------------------------
  48.  
  49. #ifndef __ASSERT_H
  50. #include <assert.h>
  51. #define __ASSERT_H
  52. #endif
  53.  
  54. #ifndef __DOS_H
  55. #include <dos.h>
  56. #define __DOS_H
  57. #endif
  58.  
  59. #ifndef __STRNG_H
  60. #include <strng.h>
  61. #endif
  62.  
  63. // End Interface Dependencies ------------------------------------------------
  64.  
  65.  
  66. // Class //
  67.  
  68. class BaseTime : public Sortable
  69. {
  70. public:
  71.             unsigned hour() const;
  72.             unsigned minute() const;
  73.             unsigned second() const;
  74.             unsigned hundredths() const;
  75.             void         setHour( unsigned char );
  76.             void         setMinute( unsigned char );
  77.             void         setSecond( unsigned char );
  78.             void         setHundredths( unsigned char );
  79.     virtual             operator String() const = 0;
  80.  
  81.     virtual classType       isA() const = 0;
  82.     virtual char            *nameOf() const = 0;
  83.     virtual hashValueType   hashValue() const;
  84.     virtual int             isEqual( const Object& ) const;
  85.     virtual int             isLessThan( const Object& ) const;
  86.     virtual void            printOn( ostream& ) const;
  87. protected:
  88.             BaseTime();
  89.             BaseTime( const BaseTime& );
  90.             BaseTime( unsigned char, unsigned char = 0, unsigned char = 0, unsigned char = 0 );
  91. private:
  92.             unsigned char HH;
  93.             unsigned char MM;
  94.             unsigned char SS;
  95.             unsigned char HD;
  96. };
  97.  
  98. // Description -------------------------------------------------------------
  99. //
  100. //         Defines a base time class.  This class provides a starting place
  101. //         for deriving usuable time classes.
  102. //
  103. // Constructors
  104. //
  105. //         BaseTime()
  106. //
  107. //     Default constructor
  108. //
  109. //         BaseTime( BaseTime& )
  110. //
  111. //     Copy constructor
  112. //
  113. //         BaseTime( H, . . . )
  114. //
  115. //         Constructs a base time object from a parameter list.
  116. //
  117. // Public Members
  118. //
  119. //         hour
  120. //
  121. //         Returns the hour portion of the base time object.
  122. //
  123. //         minute
  124. //
  125. //         Returns the hour portion of the base time object.
  126. //
  127. //         second
  128. //
  129. //         Returns the second portion of the base time object.
  130. //
  131. //         hundreths
  132. //
  133. //         Returns the hundreths portion of the base time object.
  134. //
  135. //         setHour
  136. //
  137. //         Sets the hour portion of the base time object.
  138. //
  139. //         setMinute
  140. //
  141. //         Sets the minute portion of the base time object.
  142. //
  143. //         setHundreths
  144. //
  145. //         Sets the hundreths portion of the base time object.
  146. //
  147. //         operator String()
  148. //
  149. //         Conversion operator to type string.
  150. //
  151. // Private Members
  152. //
  153. //         HH
  154. //
  155. //         The hour portion of the base time object.
  156. //
  157. //         MM
  158. //
  159. //         The minute portion of the base time object.
  160. //
  161. //         SS
  162. //
  163. //         The second portion of the base time object.
  164. //
  165. //         HD
  166. //
  167. //         The hundreths portion of the base time object.
  168. //
  169. // End ---------------------------------------------------------------------
  170.  
  171.  
  172. // Constructor //
  173.  
  174. inline BaseTime::BaseTime()
  175.  
  176. // Summary -----------------------------------------------------------------
  177. //
  178. //         Default constructor. Constructs a base time object.
  179. //
  180. // End ---------------------------------------------------------------------
  181. {
  182.     struct time t;              // From dos.h
  183.     gettime( &t );
  184.     HH = t.ti_hour;
  185.     MM = t.ti_min;
  186.     SS = t.ti_sec;
  187.     HD = t.ti_hund;
  188. }
  189. // End Constructor BaseTime::BaseTime //
  190.  
  191.  
  192. // Constructor //
  193.  
  194. inline BaseTime::BaseTime( const BaseTime& B ) :
  195.     HH(B.HH), MM(B.MM), SS(B.SS), HD(B.HD)
  196.  
  197. // Summary -----------------------------------------------------------------
  198. //
  199. //         Copy constructor.  Constructs a base time object from another
  200. //         base time object.
  201. //
  202. // Functional Description
  203. //
  204. //      We initialized each of the private data members of the class in
  205. //      the prototype, hence the function body is null.
  206. //
  207. // End ---------------------------------------------------------------------
  208. {
  209. }
  210. // End Constructor BaseTime::BaseTime //
  211.  
  212.  
  213. // Constructor //
  214.  
  215. inline BaseTime::BaseTime( unsigned char H, unsigned char M, unsigned char S, unsigned char D )
  216.  
  217. // Summary -----------------------------------------------------------------
  218. //
  219. //         Constructor.  Constructs a base time object from the given
  220. //         parameters.
  221. //
  222. // End ---------------------------------------------------------------------
  223. {
  224.     setHour( H );
  225.     setMinute( M );
  226.     setSecond( S );
  227.     setHundredths( D );
  228. }
  229. // End Constructor BaseTime::BaseTime //
  230.  
  231.  
  232. // Member Function //
  233.  
  234. inline unsigned BaseTime::hour() const
  235.  
  236. // Summary -----------------------------------------------------------------
  237. //
  238. //         Returns the hours portion of a base time object.
  239. //
  240. // End ---------------------------------------------------------------------
  241. {
  242.     return HH;
  243. }
  244. // End Member Function BaseTime::hour //
  245.  
  246.  
  247. // Member Function //
  248.  
  249. inline unsigned BaseTime::minute() const
  250.  
  251. // Summary -----------------------------------------------------------------
  252. //
  253. //         Returns the minutes portion of a base time object.
  254. //
  255. // End ---------------------------------------------------------------------
  256. {
  257.     return MM;
  258. }
  259. // End Member Function BaseTime::minute //
  260.  
  261.  
  262. // Member Function //
  263.  
  264. inline unsigned BaseTime::second() const
  265.  
  266. // Summary -----------------------------------------------------------------
  267. //
  268. //         Returns the seconds portion of a base time object.
  269. //
  270. // End ---------------------------------------------------------------------
  271. {
  272.     return SS;
  273. }
  274. // End Member Function BaseTime::second //
  275.  
  276.  
  277. // Member Function //
  278.  
  279. inline unsigned BaseTime::hundredths() const
  280.  
  281. // Summary -----------------------------------------------------------------
  282. //
  283. //         Returns the hundreths portion of a base time object.
  284. //
  285. // End ---------------------------------------------------------------------
  286. {
  287.     return HD;
  288. }
  289. // End Member Function BaseTime::hundreths //
  290.  
  291.  
  292. // Member Function //
  293.  
  294. inline void BaseTime::setHour( unsigned char anHour )
  295.  
  296. // Summary -----------------------------------------------------------------
  297. //
  298. //         Sets the hour portion of a base time object.
  299. //
  300. // End ---------------------------------------------------------------------
  301. {
  302.     assert( anHour < 24 );
  303.     HH = anHour;
  304. }
  305. // End Member Function BaseTime::setHour //
  306.  
  307.  
  308. // Member Function //
  309.  
  310. inline void BaseTime::setMinute( unsigned char M )
  311.  
  312. // Summary -----------------------------------------------------------------
  313. //
  314. //         Sets the minute portion of a base time object.
  315. //
  316. // End ---------------------------------------------------------------------
  317. {
  318.     assert( M < 60 );
  319.     MM = M;
  320. }
  321. // End Member Function BaseTime::setMinute //
  322.  
  323.  
  324. // Member Function //
  325.  
  326. inline void BaseTime::setSecond( unsigned char S )
  327.  
  328. // Summary -----------------------------------------------------------------
  329. //
  330. //         Sets the second portion of a base time object.
  331. //
  332. // End ---------------------------------------------------------------------
  333. {
  334.     assert( S < 60 );
  335.     SS = S;
  336. }
  337. // End Member Function BaseTime::setSecond //
  338.  
  339.  
  340. // Member Function //
  341.  
  342. inline void BaseTime::setHundredths( unsigned char D )
  343.  
  344. // Summary -----------------------------------------------------------------
  345. //
  346. //         Sets the hunderths portion of a base time object.
  347. //
  348. // End ---------------------------------------------------------------------
  349. {
  350.     assert( D < 100 );
  351.     HD = D;
  352. }
  353. // End Member Function BaseTime::setHundreths //
  354.  
  355.  
  356. // Class //
  357.  
  358. class Time: public BaseTime
  359. {
  360. public:
  361.             Time();
  362.             Time( const Time& );
  363.             Time( unsigned char, unsigned char = 0, unsigned char = 0, 
  364.                   unsigned char = 0 );
  365.     virtual                 operator String() const;
  366.     virtual classType       isA() const;
  367.     virtual char            *nameOf() const;
  368. };
  369.  
  370. // Description -------------------------------------------------------------
  371. //
  372. //         Defines a usable time class.
  373. //
  374. // Constructors
  375. //
  376. //         Time()
  377. //
  378. //         Default constructor
  379. //
  380. //         Time( Time& )
  381. //
  382. //         Copy constructor
  383. //
  384. //         Time( H, . . . )
  385. //
  386. //         Constructs a time object from a parameter list.
  387. //
  388. // Public Members
  389. //
  390. //         operator String()
  391. //
  392. //         Conversion operator to type string.
  393. //
  394. // Inherited Members
  395. //
  396. //         hour
  397. //
  398. //         Inherited from BaseTime
  399. //
  400. //         minute
  401. //
  402. //         Inherited from BaseTime
  403. //
  404. //         second
  405. //
  406. //         Inherited from BaseTime
  407. //
  408. //         hundreths
  409. //
  410. //         Inherited from BaseTime
  411. //
  412. //         setHour
  413. //
  414. //         Inherited from BaseTime
  415. //
  416. //         setMinute
  417. //
  418. //         Inherited from BaseTime
  419. //
  420. //         setHundreths
  421. //
  422. //         Inherited from BaseTime
  423. //
  424. // End ---------------------------------------------------------------------
  425.  
  426.  
  427. // Constructor //
  428.  
  429. inline Time::Time() : BaseTime()
  430.  
  431. // Summary -----------------------------------------------------------------
  432. //
  433. //         Default constructor.
  434. //
  435. // Functional Description
  436. //
  437. //      We construct the Time object using the constructor for BaseTime,
  438. //      hence the body of the constructor is null.
  439. //
  440. // End ---------------------------------------------------------------------
  441. {
  442. }
  443. // End Constructor Time::Time //
  444.  
  445.  
  446. // Constructor //
  447.  
  448. inline Time::Time( const Time& T ) : BaseTime( T )
  449.  
  450. // Summary -----------------------------------------------------------------
  451. //
  452. //         Copy constructor.
  453. //
  454. // Functional Description
  455. //
  456. //      We construct the Time object using the constructor for BaseTime,
  457. //      hence the body of the constructor is null.
  458. //
  459. // End ---------------------------------------------------------------------
  460. {
  461. }
  462. // End Constructor Time::Time //
  463.  
  464.  
  465. // Constructor //
  466.  
  467. inline Time::Time( unsigned char H, unsigned char M, unsigned char S, 
  468.                    unsigned char D ) :  BaseTime( H, M, S, D )
  469.  
  470. // Summary -----------------------------------------------------------------
  471. //
  472. //         Constructor from parameter list.
  473. //
  474. // Functional Description
  475. //
  476. //      We construct the Time object using the constructor for BaseTime,
  477. //      hence the body of the constructor is null.
  478. //
  479. // End ---------------------------------------------------------------------
  480. {
  481. }
  482. // End Constructor Time::Time //
  483.  
  484. #endif  // ifndef __LTIME_H //
  485.