Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.6 KiB

  1. /*
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. */
  4. #include "sdppch.h"
  5. #include "sdpltran.h"
  6. SDP_LINE_TRANSITION::SDP_LINE_TRANSITION(
  7. IN LINE_TRANSITION_INFO *LineTransitionInfo,
  8. IN DWORD NumStates
  9. )
  10. : m_IsValid(FALSE),
  11. m_LineTransitionInfo(LineTransitionInfo),
  12. m_NumStates(NumStates)
  13. {
  14. ASSERT(NULL != LineTransitionInfo);
  15. ASSERT(0 < NumStates);
  16. if ( (NULL == LineTransitionInfo) || (0 >= NumStates) )
  17. {
  18. return;
  19. }
  20. // verify each transition info structure
  21. //
  22. for ( UINT i=0; i < NumStates; i++ )
  23. {
  24. // check if the line state value is consistent with the corresponding entry
  25. ASSERT(LineTransitionInfo[i].m_LineState == i);
  26. if ( LineTransitionInfo[i].m_LineState != i )
  27. {
  28. return;
  29. }
  30. // check that the separator character string is initialized (NULL)
  31. ASSERT(NULL == LineTransitionInfo[i].m_SeparatorChars);
  32. if ( NULL != LineTransitionInfo[i].m_SeparatorChars )
  33. {
  34. return;
  35. }
  36. }
  37. m_IsValid = TRUE;
  38. // prepare separator character arrays for each of the line transition states
  39. for ( i=0; i < NumStates; i++ )
  40. {
  41. CHAR *SeparatorChars;
  42. // allocate memory for the separator characters
  43. try
  44. {
  45. SeparatorChars = new CHAR[LineTransitionInfo[i].m_NumTransitions];
  46. }
  47. catch(...)
  48. {
  49. SeparatorChars = NULL;
  50. }
  51. if( NULL == SeparatorChars)
  52. {
  53. LineTransitionInfo[i].m_SeparatorChars = NULL;
  54. continue;
  55. }
  56. // copy each separator character into the character array
  57. for ( UINT j=0; j < LineTransitionInfo[i].m_NumTransitions; j++ )
  58. {
  59. SeparatorChars[j] = LineTransitionInfo[i].m_Transitions[j].m_SeparatorChar;
  60. }
  61. LineTransitionInfo[i].m_SeparatorChars = SeparatorChars;
  62. }
  63. return;
  64. }
  65. SDP_LINE_TRANSITION::~SDP_LINE_TRANSITION(
  66. )
  67. {
  68. // if the m_IsValid flag is set, then the separator character arrays must have
  69. // been filled and need to be freed
  70. if ( IsValid() )
  71. {
  72. for ( UINT i=0; i < m_NumStates; i++ )
  73. {
  74. // this check is necessary for situations in which new raised exception when
  75. // allocating the character arrays in the constructor
  76. if ( NULL != m_LineTransitionInfo[i].m_SeparatorChars )
  77. {
  78. delete m_LineTransitionInfo[i].m_SeparatorChars;
  79. }
  80. }
  81. }
  82. }