text stringlengths 54 60.6k |
|---|
<commit_before>5a880736-2e4d-11e5-9284-b827eb9e62be<commit_msg>5a8d22a2-2e4d-11e5-9284-b827eb9e62be<commit_after>5a8d22a2-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>14d08914-2e4f-11e5-9284-b827eb9e62be<commit_msg>14d59fc6-2e4f-11e5-9284-b827eb9e62be<commit_after>14d59fc6-2e4f-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>19e39c86-2e4d-11e5-9284-b827eb9e62be<commit_msg>19e8b0a4-2e4d-11e5-9284-b827eb9e62be<commit_after>19e8b0a4-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>1f8e3aec-2e4d-11e5-9284-b827eb9e62be<commit_msg>1f933628-2e4d-11e5-9284-b827eb9e62be<commit_after>1f933628-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>59355c30-2e4d-11e5-9284-b827eb9e62be<commit_msg>593a67b6-2e4d-11e5-9284-b827eb9e62be<commit_after>593a67b6-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>7de34b40-2e4e-11e5-9284-b827eb9e62be<commit_msg>7de85d42-2e4e-11e5-9284-b827eb9e62be<commit_after>7de85d42-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>b33c9dec-2e4d-11e5-9284-b827eb9e62be<commit_msg>b3418f14-2e4d-11e5-9284-b827eb9e62be<commit_after>b3418f14-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>c4d317f6-2e4e-11e5-9284-b827eb9e62be<commit_msg>c4d80a2c-2e4e-11e5-9284-b827eb9e62be<commit_after>c4d80a2c-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>291170fa-2e4f-11e5-9284-b827eb9e62be<commit_msg>291662fe-2e4f-11e5-9284-b827eb9e62be<commit_after>291662fe-2e4f-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>530316e0-2e4d-11e5-9284-b827eb9e62be<commit_msg>530aa81a-2e4d-11e5-9284-b827eb9e62be<commit_after>530aa81a-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>f41ae0ca-2e4e-11e5-9284-b827eb9e62be<commit_msg>f42035e8-2e4e-11e5-9284-b827eb9e62be<commit_after>f42035e8-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>1418237a-2e4e-11e5-9284-b827eb9e62be<commit_msg>141d1696-2e4e-11e5-9284-b827eb9e62be<commit_after>141d1696-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>fb59ac7e-2e4c-11e5-9284-b827eb9e62be<commit_msg>fb5ea0da-2e4c-11e5-9284-b827eb9e62be<commit_after>fb5ea0da-2e4c-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>eee83c88-2e4e-11e5-9284-b827eb9e62be<commit_msg>eeed3d78-2e4e-11e5-9284-b827eb9e62be<commit_after>eeed3d78-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>70f7b4d4-2e4e-11e5-9284-b827eb9e62be<commit_msg>70fcaf20-2e4e-11e5-9284-b827eb9e62be<commit_after>70fcaf20-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>f9f20e94-2e4c-11e5-9284-b827eb9e62be<commit_msg>f9f7050c-2e4c-11e5-9284-b827eb9e62be<commit_after>f9f7050c-2e4c-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>3749fd40-2e4f-11e5-9284-b827eb9e62be<commit_msg>374ef5f2-2e4f-11e5-9284-b827eb9e62be<commit_after>374ef5f2-2e4f-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>e7eddbec-2e4c-11e5-9284-b827eb9e62be<commit_msg>e7f2eaec-2e4c-11e5-9284-b827eb9e62be<commit_after>e7f2eaec-2e4c-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>0dd06a46-2e4d-11e5-9284-b827eb9e62be<commit_msg>0dd576e4-2e4d-11e5-9284-b827eb9e62be<commit_after>0dd576e4-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>40224212-2e4d-11e5-9284-b827eb9e62be<commit_msg>402749d8-2e4d-11e5-9284-b827eb9e62be<commit_after>402749d8-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>1160cbce-2e4d-11e5-9284-b827eb9e62be<commit_msg>1165c2fa-2e4d-11e5-9284-b827eb9e62be<commit_after>1165c2fa-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>3ab89216-2e4f-11e5-9284-b827eb9e62be<commit_msg>3abd871c-2e4f-11e5-9284-b827eb9e62be<commit_after>3abd871c-2e4f-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>b4bbb7fc-2e4d-11e5-9284-b827eb9e62be<commit_msg>b4c0a848-2e4d-11e5-9284-b827eb9e62be<commit_after>b4c0a848-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>56888b24-2e4d-11e5-9284-b827eb9e62be<commit_msg>568d8c64-2e4d-11e5-9284-b827eb9e62be<commit_after>568d8c64-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>d6ad3ede-2e4e-11e5-9284-b827eb9e62be<commit_msg>d6b24334-2e4e-11e5-9284-b827eb9e62be<commit_after>d6b24334-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>555d54dc-2e4d-11e5-9284-b827eb9e62be<commit_msg>55625806-2e4d-11e5-9284-b827eb9e62be<commit_after>55625806-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>195744a2-2e4d-11e5-9284-b827eb9e62be<commit_msg>195c5de8-2e4d-11e5-9284-b827eb9e62be<commit_after>195c5de8-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>e4b11bf6-2e4c-11e5-9284-b827eb9e62be<commit_msg>e4b62114-2e4c-11e5-9284-b827eb9e62be<commit_after>e4b62114-2e4c-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>b89ad44c-2e4e-11e5-9284-b827eb9e62be<commit_msg>b89feab8-2e4e-11e5-9284-b827eb9e62be<commit_after>b89feab8-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>8cb9f322-2e4d-11e5-9284-b827eb9e62be<commit_msg>8cbf22b6-2e4d-11e5-9284-b827eb9e62be<commit_after>8cbf22b6-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>43aa13a6-2e4d-11e5-9284-b827eb9e62be<commit_msg>43af1590-2e4d-11e5-9284-b827eb9e62be<commit_after>43af1590-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>f76708ea-2e4d-11e5-9284-b827eb9e62be<commit_msg>f76c00f2-2e4d-11e5-9284-b827eb9e62be<commit_after>f76c00f2-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>c54345d6-2e4d-11e5-9284-b827eb9e62be<commit_msg>c5483a6e-2e4d-11e5-9284-b827eb9e62be<commit_after>c5483a6e-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>c169b4da-2e4e-11e5-9284-b827eb9e62be<commit_msg>c16efba2-2e4e-11e5-9284-b827eb9e62be<commit_after>c16efba2-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>0d72b6b6-2e4e-11e5-9284-b827eb9e62be<commit_msg>0d77ae8c-2e4e-11e5-9284-b827eb9e62be<commit_after>0d77ae8c-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>c1b8c832-2e4d-11e5-9284-b827eb9e62be<commit_msg>c1bdd3e0-2e4d-11e5-9284-b827eb9e62be<commit_after>c1bdd3e0-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>bcad53f2-2e4e-11e5-9284-b827eb9e62be<commit_msg>bcb26d92-2e4e-11e5-9284-b827eb9e62be<commit_after>bcb26d92-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>ff15526c-2e4e-11e5-9284-b827eb9e62be<commit_msg>ff1a4858-2e4e-11e5-9284-b827eb9e62be<commit_after>ff1a4858-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>c064c0f8-2e4d-11e5-9284-b827eb9e62be<commit_msg>c069b9d2-2e4d-11e5-9284-b827eb9e62be<commit_after>c069b9d2-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>0657735c-2e4f-11e5-9284-b827eb9e62be<commit_msg>065cd6ee-2e4f-11e5-9284-b827eb9e62be<commit_after>065cd6ee-2e4f-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>2de9d780-2e4e-11e5-9284-b827eb9e62be<commit_msg>2deef008-2e4e-11e5-9284-b827eb9e62be<commit_after>2deef008-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>c767fc12-2e4d-11e5-9284-b827eb9e62be<commit_msg>c76cf7a8-2e4d-11e5-9284-b827eb9e62be<commit_after>c76cf7a8-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>4bc6e384-2e4d-11e5-9284-b827eb9e62be<commit_msg>4bcc06b6-2e4d-11e5-9284-b827eb9e62be<commit_after>4bcc06b6-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>ec1c63fe-2e4d-11e5-9284-b827eb9e62be<commit_msg>ec21879e-2e4d-11e5-9284-b827eb9e62be<commit_after>ec21879e-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>99bd6878-2e4e-11e5-9284-b827eb9e62be<commit_msg>99c28f2e-2e4e-11e5-9284-b827eb9e62be<commit_after>99c28f2e-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>f6f05b4a-2e4e-11e5-9284-b827eb9e62be<commit_msg>f6f55aa0-2e4e-11e5-9284-b827eb9e62be<commit_after>f6f55aa0-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>ea82faa4-2e4c-11e5-9284-b827eb9e62be<commit_msg>ea87ed0c-2e4c-11e5-9284-b827eb9e62be<commit_after>ea87ed0c-2e4c-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>a0966d7a-2e4e-11e5-9284-b827eb9e62be<commit_msg>a09b676c-2e4e-11e5-9284-b827eb9e62be<commit_after>a09b676c-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>8fb87ad0-2e4d-11e5-9284-b827eb9e62be<commit_msg>8fbd79e0-2e4d-11e5-9284-b827eb9e62be<commit_after>8fbd79e0-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>08ae0992-2e4d-11e5-9284-b827eb9e62be<commit_msg>08b319f0-2e4d-11e5-9284-b827eb9e62be<commit_after>08b319f0-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>859b2c7c-2e4e-11e5-9284-b827eb9e62be<commit_msg>85a0355a-2e4e-11e5-9284-b827eb9e62be<commit_after>85a0355a-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>385a4226-2e4f-11e5-9284-b827eb9e62be<commit_msg>385f3b8c-2e4f-11e5-9284-b827eb9e62be<commit_after>385f3b8c-2e4f-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>b0aae48a-2e4d-11e5-9284-b827eb9e62be<commit_msg>b0afec50-2e4d-11e5-9284-b827eb9e62be<commit_after>b0afec50-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>ab9e5dc4-2e4c-11e5-9284-b827eb9e62be<commit_msg>aba352d4-2e4c-11e5-9284-b827eb9e62be<commit_after>aba352d4-2e4c-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>123c5022-2e4d-11e5-9284-b827eb9e62be<commit_msg>12413b8c-2e4d-11e5-9284-b827eb9e62be<commit_after>12413b8c-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>ae1d04b0-2e4c-11e5-9284-b827eb9e62be<commit_msg>ae21fc5e-2e4c-11e5-9284-b827eb9e62be<commit_after>ae21fc5e-2e4c-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>d7154d4a-2e4d-11e5-9284-b827eb9e62be<commit_msg>d71a4c00-2e4d-11e5-9284-b827eb9e62be<commit_after>d71a4c00-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>55e0c3f8-2e4d-11e5-9284-b827eb9e62be<commit_msg>55e5ce3e-2e4d-11e5-9284-b827eb9e62be<commit_after>55e5ce3e-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>264a61e4-2e4d-11e5-9284-b827eb9e62be<commit_msg>264fa0be-2e4d-11e5-9284-b827eb9e62be<commit_after>264fa0be-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>917b54d6-2e4e-11e5-9284-b827eb9e62be<commit_msg>9180e6da-2e4e-11e5-9284-b827eb9e62be<commit_after>9180e6da-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>d402893c-2e4e-11e5-9284-b827eb9e62be<commit_msg>d4078004-2e4e-11e5-9284-b827eb9e62be<commit_after>d4078004-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>5eb89130-2e4e-11e5-9284-b827eb9e62be<commit_msg>5ebd8906-2e4e-11e5-9284-b827eb9e62be<commit_after>5ebd8906-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>bad92a58-2e4c-11e5-9284-b827eb9e62be<commit_msg>bade1db0-2e4c-11e5-9284-b827eb9e62be<commit_after>bade1db0-2e4c-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>b0851bd4-2e4c-11e5-9284-b827eb9e62be<commit_msg>b08a0c16-2e4c-11e5-9284-b827eb9e62be<commit_after>b08a0c16-2e4c-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>085ce24c-2e4d-11e5-9284-b827eb9e62be<commit_msg>0861ee36-2e4d-11e5-9284-b827eb9e62be<commit_after>0861ee36-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>968a6160-2e4e-11e5-9284-b827eb9e62be<commit_msg>968f76e6-2e4e-11e5-9284-b827eb9e62be<commit_after>968f76e6-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>5ea76a50-2e4d-11e5-9284-b827eb9e62be<commit_msg>5eac74d2-2e4d-11e5-9284-b827eb9e62be<commit_after>5eac74d2-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>0f20190e-2e4e-11e5-9284-b827eb9e62be<commit_msg>0f251102-2e4e-11e5-9284-b827eb9e62be<commit_after>0f251102-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>0857ac28-2e4d-11e5-9284-b827eb9e62be<commit_msg>085ce24c-2e4d-11e5-9284-b827eb9e62be<commit_after>085ce24c-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>0bd7f12c-2e4e-11e5-9284-b827eb9e62be<commit_msg>0bdce86c-2e4e-11e5-9284-b827eb9e62be<commit_after>0bdce86c-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>9a7322a8-2e4e-11e5-9284-b827eb9e62be<commit_msg>9a784d5a-2e4e-11e5-9284-b827eb9e62be<commit_after>9a784d5a-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>ccca9562-2e4c-11e5-9284-b827eb9e62be<commit_msg>cccfd4aa-2e4c-11e5-9284-b827eb9e62be<commit_after>cccfd4aa-2e4c-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>506520cc-2e4d-11e5-9284-b827eb9e62be<commit_msg>506a2932-2e4d-11e5-9284-b827eb9e62be<commit_after>506a2932-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>9c4e388e-2e4d-11e5-9284-b827eb9e62be<commit_msg>9c63b15a-2e4d-11e5-9284-b827eb9e62be<commit_after>9c63b15a-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>6b9748e8-2e4d-11e5-9284-b827eb9e62be<commit_msg>6b9c94ce-2e4d-11e5-9284-b827eb9e62be<commit_after>6b9c94ce-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>6e217f4c-2e4e-11e5-9284-b827eb9e62be<commit_msg>6e267cf4-2e4e-11e5-9284-b827eb9e62be<commit_after>6e267cf4-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>18697ac8-2e4e-11e5-9284-b827eb9e62be<commit_msg>186e6f38-2e4e-11e5-9284-b827eb9e62be<commit_after>186e6f38-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>4510677c-2e4d-11e5-9284-b827eb9e62be<commit_msg>45155c14-2e4d-11e5-9284-b827eb9e62be<commit_after>45155c14-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>0814f638-2e4f-11e5-9284-b827eb9e62be<commit_msg>0819f462-2e4f-11e5-9284-b827eb9e62be<commit_after>0819f462-2e4f-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>63a9baac-2e4e-11e5-9284-b827eb9e62be<commit_msg>63aec182-2e4e-11e5-9284-b827eb9e62be<commit_after>63aec182-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>6abf9212-2e4e-11e5-9284-b827eb9e62be<commit_msg>6ac4bb8e-2e4e-11e5-9284-b827eb9e62be<commit_after>6ac4bb8e-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>d464701c-2e4d-11e5-9284-b827eb9e62be<commit_msg>d4696a90-2e4d-11e5-9284-b827eb9e62be<commit_after>d4696a90-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>749341fe-2e4d-11e5-9284-b827eb9e62be<commit_msg>74982f84-2e4d-11e5-9284-b827eb9e62be<commit_after>74982f84-2e4d-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>ea8104ea-2e4e-11e5-9284-b827eb9e62be<commit_msg>ea862dbc-2e4e-11e5-9284-b827eb9e62be<commit_after>ea862dbc-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>921fe2c6-2e4e-11e5-9284-b827eb9e62be<commit_msg>9224d6dc-2e4e-11e5-9284-b827eb9e62be<commit_after>9224d6dc-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>1aff6af4-2e4e-11e5-9284-b827eb9e62be<commit_msg>1b047300-2e4e-11e5-9284-b827eb9e62be<commit_after>1b047300-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>8676d218-2e4e-11e5-9284-b827eb9e62be<commit_msg>867bd9ca-2e4e-11e5-9284-b827eb9e62be<commit_after>867bd9ca-2e4e-11e5-9284-b827eb9e62be<|endoftext|> |
<commit_before>#ifndef AMGCL_IO_BINARY_HPP
#define AMGCL_IO_BINARY_HPP
/*
The MIT License
Copyright (c) 2012-2016 Denis Demidov <dennis.demidov@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* \file amgcl/io/binary.hpp
* \author Denis Demidov <dennis.demidov@gmail.com>
* \brief Convenience functions for binary file I/O.
*/
#include <vector>
#include <fstream>
namespace amgcl {
namespace io {
/// Read single value from a binary file.
template <class T>
bool read(std::ifstream &f, T &val) {
return f.read((char*)&val, sizeof(T));
}
/// Read vector from a binary file.
template <class T>
bool read(std::ifstream &f, std::vector<T> &vec) {
return f.read((char*)&vec[0], sizeof(T) * vec.size());
}
/// Write single value to a binary file.
template <class T>
bool write(std::ofstream &f, const T &val) {
return f.write((char*)&val, sizeof(T));
}
/// Write vector to a binary file.
template <class T>
bool write(std::ofstream &f, const std::vector<T> &vec) {
return f.write((char*)&vec[0], sizeof(T) * vec.size());
}
} // namespace io
} // namespace amgcl
#endif
<commit_msg>Explicitly convert fstream to bool<commit_after>#ifndef AMGCL_IO_BINARY_HPP
#define AMGCL_IO_BINARY_HPP
/*
The MIT License
Copyright (c) 2012-2016 Denis Demidov <dennis.demidov@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* \file amgcl/io/binary.hpp
* \author Denis Demidov <dennis.demidov@gmail.com>
* \brief Convenience functions for binary file I/O.
*/
#include <vector>
#include <fstream>
namespace amgcl {
namespace io {
/// Read single value from a binary file.
template <class T>
bool read(std::ifstream &f, T &val) {
return static_cast<bool>(f.read((char*)&val, sizeof(T)));
}
/// Read vector from a binary file.
template <class T>
bool read(std::ifstream &f, std::vector<T> &vec) {
return static_cast<bool>(f.read((char*)&vec[0], sizeof(T) * vec.size()));
}
/// Write single value to a binary file.
template <class T>
bool write(std::ofstream &f, const T &val) {
return static_cast<bool>(f.write((char*)&val, sizeof(T)));
}
/// Write vector to a binary file.
template <class T>
bool write(std::ofstream &f, const std::vector<T> &vec) {
return static_cast<bool>(f.write((char*)&vec[0], sizeof(T) * vec.size()));
}
} // namespace io
} // namespace amgcl
#endif
<|endoftext|> |
<commit_before>#include <stdio.h>
#include <algorithm> // std::sort
#include <vector>
#include <stack>
// We will user a pair for the queries:
// (R, x) and (Q, -1) where the -1 is ignored
typedef std::pair<char, int> Query;
// Class Edge
// Members: first_, second_, removed_
// Description: Class that contains in first and second the
// vertex that conform the edge. Removed is a label
// that is used to check whether the edge is in the graph or not
class Edge {
public:
Edge();
Edge(int,int);
int first_, second_;
bool removed() { return removed_; }
void remove() { removed_ = true; }
private:
bool removed_;
};
Edge::Edge() {
first_ = -1;
second_ = -1;
removed_ = false;
}
Edge::Edge(int first, int second) {
first_ = first;
second_ = second;
removed_ = false;
}
// Class DisjointSets
// Description: We will use the disjoint sets data structure with
// some modifications to handle the connected components representation
// We will only document functions that are not implemented in a
// common disjoint sets structure.
// For further information http://en.wikipedia.org/wiki/Disjoint-set_data_structure
class DisjointSets {
public:
DisjointSets();
~DisjointSets();
DisjointSets(int size);
void unify(int,int);
int find(int);
std::vector<int> representatives() { return representatives_; }
std::vector<int> ranks() { return ranks_; }
std::vector<int> sizes() { return sizes_; }
int size() { return size_; }
int components() { return components_; }
// Function: countPairs()
// This a function that will count the number of
// pair of nodes that are not connected in the graph
unsigned long long countPairs();
private:
std::vector<int> representatives_;
std::vector<int> ranks_;
std::vector<int> sizes_; // Size of each component in the graph.
// Component represented by 'i' will have its size in sizes_[i].
int components_; // Current number of components
int size_; // Number of vertex in the graph
};
DisjointSets::DisjointSets(int size) {
// We will go until size + 1 to handle 1-indexed edges
for (int i = 0; i < size + 1; ++i) {
representatives_.push_back(i);
ranks_.push_back(0);
sizes_.push_back(1);
}
size_ = size;
components_ = size;
}
DisjointSets::~DisjointSets() {
}
int DisjointSets::find(int id) {
// id between 1 and size + 1 to handle 1-indexed edges
if (1 <= id && id < size_ + 1) {
if (representatives_[id] == id) {
return id;
} else {
representatives_[id] = this->find(representatives_[id]);
return representatives_[id];
}
}
return -1;
}
void DisjointSets::unify(int a, int b) {
int arep = this->find(a);
int brep = this->find(b);
if (arep == -1 || brep == -1)
return;
// If they are on different disjoint sets
if (arep != brep) {
if (ranks_[arep] > ranks_[brep]) {
representatives_[brep] = arep;
sizes_[arep] += sizes_[brep];
} else if (ranks_[arep] < ranks_[brep]) {
representatives_[arep] = brep;
sizes_[brep] += sizes_[arep];
} else {
representatives_[arep] = brep;
sizes_[brep] += sizes_[arep];
++ranks_[brep];
}
// Every unification decreases the number of components
--components_;
}
}
unsigned long long DisjointSets::countPairs() {
std::vector<int> sortedSizes(sizes_);
// Sorting the array of sizes so we ensure that in the first
// components_ positions we will have all the components sizes
std::sort(sortedSizes.begin(), sortedSizes.end(), std::greater<int>());
// Number of disconnected pairs is defined by
// SUM ( PROD ( A[i], A[j] ) ) for 0 <= i <= components_ and i + 1 <= j <= components_
unsigned long long pairs = 0;
for (int i = 0; i < components_; ++i) {
for (int j = i + 1; j < components_; ++j) {
pairs += sortedSizes[i] * sortedSizes[j];
}
}
return pairs;
}
// Function: disconnectedOffices
// Arguments: edges : vector of Edge, queries: vector of Query
// Description: This function does the following:
// 1 -> Removes all edges that are asked to be removed in the queries
// 2 -> Going backwards in queries:
// if there's a 'Q' query ->
// it pushes the number of pairs disconnected
// in the current graph (using countPairs()) to
// a stack 'pairs'
// if there's a 'R x' query ->
// it unifies the vertex in edge[x].
// 3 -> Finally, it pops each elem in 'pairs' and print it
void disconnectedOffices(std::vector<Edge>& edges, std::stack<Query>& queries) {
int nVertex = edges.size();
// Graph without edges (separated components)
DisjointSets components(nVertex);
std::stack<unsigned long long> pairs;
int frep, srep;
unsigned long long nPairs = (nVertex * (nVertex - 1)) / 2;
// Unify not labeled edges
for (auto edge : edges) {
if (!edge.removed()) {
frep = components.find(edge.first_);
srep = components.find(edge.second_);
if (frep == srep) {
continue;
}
nPairs -= components.sizes()[frep] * components.sizes()[srep];
components.unify(edge.first_, edge.second_);
}
}
int N = queries.size();
// Going backwards on the queries
for (int i = N - 1; i >= 0; --i) {
Query& query = queries.top();
queries.pop();
// If there's a 'show' query, we count the pairs and push into the results
if (query.first == 'Q') {
pairs.push(nPairs);
// If it's a remove query, unify the removed edges
} else {
Edge& edge = edges[query.second];
frep = components.find(edge.first_);
srep = components.find(edge.second_);
if (frep == srep) {
continue;
}
nPairs -= components.sizes()[frep] * components.sizes()[srep];
components.unify(edge.first_, edge.second_);
}
}
// Print number of pairs in the right order
while (!pairs.empty()) {
printf("%llu\n", pairs.top());
pairs.pop();
}
}
int main() {
int cases;
scanf("%d", &cases);
for (; cases > 0; --cases) {
int N;
scanf("%d", &N);
std::vector<Edge> edges;
edges.reserve(N - 1);
// Handling 1-indexed edges
edges.push_back(Edge());
// Push edges in vector
for (int i = 0; i < N - 1; ++i) {
int first, second;
scanf("%d %d", &first, &second);
//printf("%d %d\n", first, second);
edges.push_back(Edge(first, second));
}
int M, vertex;
std::stack<Query> queries;
char query;
scanf("%d", &M);
// Push queries in vector
for (; M > 0; --M) {
scanf(" %c", &query);
// Queries 'Q' will have vertex = -1
vertex = -1;
// Queries 'R x' will have vertex = x
if (query == 'R') {
scanf("%d", &vertex);
edges[vertex].remove();
}
//printf("%c %d\n", query, vertex);
queries.push(std::make_pair(query, vertex));
}
// Print number of paris disconnected
disconnectedOffices(edges, queries);
if (cases > 1) printf("\n"); // endline
}
return 0;
}
<commit_msg>Removed countPairs<commit_after>#include <stdio.h>
#include <algorithm> // std::sort
#include <vector>
#include <stack>
// We will user a pair for the queries:
// (R, x) and (Q, -1) where the -1 is ignored
typedef std::pair<char, int> Query;
// Class Edge
// Members: first_, second_, removed_
// Description: Class that contains in first and second the
// vertex that conform the edge. Removed is a label
// that is used to check whether the edge is in the graph or not
class Edge {
public:
Edge();
Edge(int,int);
int first_, second_;
bool removed() { return removed_; }
void remove() { removed_ = true; }
private:
bool removed_;
};
Edge::Edge() {
first_ = -1;
second_ = -1;
removed_ = false;
}
Edge::Edge(int first, int second) {
first_ = first;
second_ = second;
removed_ = false;
}
// Class DisjointSets
// Description: We will use the disjoint sets data structure with
// some modifications to handle the connected components representation
// We will only document functions that are not implemented in a
// common disjoint sets structure.
// For further information http://en.wikipedia.org/wiki/Disjoint-set_data_structure
class DisjointSets {
public:
DisjointSets();
~DisjointSets();
DisjointSets(int size);
void unify(int,int);
int find(int);
std::vector<int> representatives() { return representatives_; }
std::vector<int> ranks() { return ranks_; }
std::vector<int> sizes() { return sizes_; }
int size() { return size_; }
private:
std::vector<int> representatives_;
std::vector<int> ranks_;
std::vector<int> sizes_; // Size of each component in the graph.
// Component represented by 'i' will have its size in sizes_[i].
int size_; // Number of vertex in the graph
};
DisjointSets::DisjointSets(int size) {
// We will go until size + 1 to handle 1-indexed edges
for (int i = 0; i < size + 1; ++i) {
representatives_.push_back(i);
ranks_.push_back(0);
sizes_.push_back(1);
}
size_ = size;
}
DisjointSets::~DisjointSets() {
}
int DisjointSets::find(int id) {
// id between 1 and size + 1 to handle 1-indexed edges
if (1 <= id && id < size_ + 1) {
if (representatives_[id] == id) {
return id;
} else {
representatives_[id] = this->find(representatives_[id]);
return representatives_[id];
}
}
return -1;
}
void DisjointSets::unify(int a, int b) {
int arep = this->find(a);
int brep = this->find(b);
if (arep == -1 || brep == -1)
return;
// If they are on different disjoint sets
if (arep != brep) {
if (ranks_[arep] > ranks_[brep]) {
representatives_[brep] = arep;
sizes_[arep] += sizes_[brep];
} else if (ranks_[arep] < ranks_[brep]) {
representatives_[arep] = brep;
sizes_[brep] += sizes_[arep];
} else {
representatives_[arep] = brep;
sizes_[brep] += sizes_[arep];
++ranks_[brep];
}
}
}
// Function: disconnectedOffices
// Arguments: edges : vector of Edge, queries: vector of Query
// Description: This function does the following:
// 1 -> Removes all edges that are asked to be removed in the queries
// 2 -> Going backwards in queries:
// if there's a 'Q' query ->
// it pushes the number of pairs disconnected
// in the current graph (using countPairs()) to
// a stack 'pairs'
// if there's a 'R x' query ->
// it unifies the vertex in edge[x].
// 3 -> Finally, it pops each elem in 'pairs' and print it
void disconnectedOffices(std::vector<Edge>& edges, std::stack<Query>& queries) {
int nVertex = edges.size();
// Graph without edges (separated components)
DisjointSets components(nVertex);
std::stack<unsigned long long> pairs;
int frep, srep;
unsigned long long nPairs = (nVertex * (nVertex - 1)) / 2;
// Unify not labeled edges
for (auto edge : edges) {
if (!edge.removed()) {
frep = components.find(edge.first_);
srep = components.find(edge.second_);
if (frep == srep) {
continue;
}
nPairs -= components.sizes()[frep] * components.sizes()[srep];
components.unify(edge.first_, edge.second_);
}
}
int N = queries.size();
// Going backwards on the queries
for (int i = N - 1; i >= 0; --i) {
Query& query = queries.top();
queries.pop();
// If there's a 'show' query, we count the pairs and push into the results
if (query.first == 'Q') {
pairs.push(nPairs);
// If it's a remove query, unify the removed edges
} else {
Edge& edge = edges[query.second];
frep = components.find(edge.first_);
srep = components.find(edge.second_);
if (frep == srep) {
continue;
}
nPairs -= components.sizes()[frep] * components.sizes()[srep];
components.unify(edge.first_, edge.second_);
}
}
// Print number of pairs in the right order
while (!pairs.empty()) {
printf("%llu\n", pairs.top());
pairs.pop();
}
}
int main() {
int cases;
scanf("%d", &cases);
for (; cases > 0; --cases) {
int N;
scanf("%d", &N);
std::vector<Edge> edges;
edges.reserve(N - 1);
// Handling 1-indexed edges
edges.push_back(Edge());
// Push edges in vector
for (int i = 0; i < N - 1; ++i) {
int first, second;
scanf("%d %d", &first, &second);
//printf("%d %d\n", first, second);
edges.push_back(Edge(first, second));
}
int M, vertex;
std::stack<Query> queries;
char query;
scanf("%d", &M);
// Push queries in vector
for (; M > 0; --M) {
scanf(" %c", &query);
// Queries 'Q' will have vertex = -1
vertex = -1;
// Queries 'R x' will have vertex = x
if (query == 'R') {
scanf("%d", &vertex);
edges[vertex].remove();
}
//printf("%c %d\n", query, vertex);
queries.push(std::make_pair(query, vertex));
}
// Print number of paris disconnected
disconnectedOffices(edges, queries);
if (cases > 1) printf("\n"); // endline
}
return 0;
}
<|endoftext|> |
<commit_before>class Solution {
public:
/*
* param k : As description.
* param n : As description.
* return: How many k's between 0 and n.
*/
int digitCounts(int k, int n) {
// write your code here
if (k<0 or k>10) return 0;
int rt_count=0,tmp_count=0;
int i,j,ys=0,n_it=n;
i=1;
int yc=0; //right
while (n_it>0){
tmp_count=0;
ys=n_it%10;
yc=yc*10+ys;
n_it=n_it/10;
tmp_count+=i*n_it;
if (ys>=k) rt_count+=1;
i*=10;
}
return rt_count;
}
};
//O(n *log(n)) solution ,not so great
// class Solution {
// public:
// // param k : description of k
// // param n : description of n
// // return ans a integer
// int digitCounts(int k, int n) {
// int count = 0;
// if (k == 0) {
// count = 1;
// }
// for (int i = 1; i <= n; i++) {
// int number = i;
// while (number > 0) {
// if (number % 10 == k) {
// count += 1;
// }
// number /= 10;
// }
// }
// return count;
// }
// };<commit_msg>testing 3<commit_after>class Solution {
public:
/*
* param k : As description.
* param n : As description.
* return: How many k's between 0 and n.
*/
int digitCounts(int k, int n) {
// write your code here
if (k<0 or k>10) return 0;
int rt_count=0,tmp_count=0;
int i,j,ys=0,n_it=n;
i=1;
int yc=0; //right
while (n_it>0){
tmp_count=0;
ys=n_it%10; // this digit
n_it=n_it/10;
rt_count+=i*n_it;
if (ys==k) rt_count += yc+1;
if (ys>k) rt_count+=i;
i*=10;
yc=yc*10+ys; //right total
}
return rt_count;
}
};
//O(n *log(n)) solution ,not so great
// class Solution {
// public:
// // param k : description of k
// // param n : description of n
// // return ans a integer
// int digitCounts(int k, int n) {
// int count = 0;
// if (k == 0) {
// count = 1;
// }
// for (int i = 1; i <= n; i++) {
// int number = i;
// while (number > 0) {
// if (number % 10 == k) {
// count += 1;
// }
// number /= 10;
// }
// }
// return count;
// }
// };<|endoftext|> |
<commit_before>#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <iomanip>
#include <map>
#include <cmath>
struct LogEntry {
long long time;
int bitrate;
double total_streamed;
operator long long () const { return this->time; }
};
constexpr double MS_PER_SEC = 10 * 10 * 10;
using LogEntries = std::vector<LogEntry>;
void repl(const LogEntries&, std::size_t);
void read_entries(LogEntries&, std::size_t);
LogEntries reorder(LogEntries&);
#ifdef DEBUG
template <typename T>
std::ostream &operator << (std::ostream&, const std::vector<T>&);
std::ostream &operator << (std::ostream&, const LogEntry&);
#endif
int main() {
// Remove synchronization between cstdio and iostream
std::ios_base::sync_with_stdio(false);
// Prevent flushing of output stream before each io operation
std::cin.tie(nullptr);
LogEntries logEntries;
std::size_t logsize;
std::cin >> logsize;
read_entries(logEntries, logsize);
#ifdef DEBUG
std::cout << "\n" << logEntries << "\n\n";
#endif
logEntries = reorder(logEntries);
#ifdef DEBUG
std::cout << "Count: " << logEntries.size() << '\n';
std::cout << logEntries << "\n\n";
#endif
if (std::cin >> logsize) {
repl(logEntries, logsize);
}
return 0;
}
/**
* @brief Reads time ranges and sells lambourghinis'
* @details The repl stands for READ-EVALUATE-PRINT-LOOP.
* This method in particular will read any time range given, determine which log entries
* fall under this time range. It will then take the streams available under this
* time range and print what percentage of those streams were fully contained
* within the range given
*
* @param entries The collection of logs. This must have gone through the reorder
* function before it can be used here
* @param count The number of queries to expect
*/
void repl(const LogEntries& entries, std::size_t count) {
LogEntries::const_iterator hi, lo;
long long start, end;
double streamed;
std::cout.precision(3);
std::cout.setf(std::ios_base::fixed);
for (std::cin >> start >> end; count--; std::cin >> start >> end) {
lo = std::lower_bound(entries.begin(), entries.end(), start);
hi = std::upper_bound(lo, entries.end(), end);
if (hi == entries.end()) {
end = (hi - 1)->time;
}
#ifdef DEBUG
std::cout << lo->time << " <= " << start << "\n"
<< (hi == entries.end() ? hi - 1 : hi)->time << " >= " << end << std::endl;
#endif
streamed = (lo->time - start) / MS_PER_SEC * (lo == entries.begin() ? 0 : (lo - 1)->bitrate)
+ (hi - 1)->total_streamed - lo->total_streamed +
(end - (hi - 1)->time) / MS_PER_SEC * (hi - 1)->bitrate;
std::cout << streamed << '\n';
}
}
/**
* @brief Aranges the logs into non overlapping ranges for easier usage
* @details The logs are taken one by one and we cut them up into smaller
* logs which do not overlap. By doing this, it is easier to work with ranges
* because you don't have to worry about anything they overlap
*
* @param entries The initial entries we got as input
*/
LogEntries reorder(LogEntries &entries) {
std::sort(entries.begin(), entries.end(),
[](const LogEntry& lhs, const LogEntry& rhs) {
return lhs.time < rhs.time;
});
LogEntries merged;
int bits = 0;
LogEntries::iterator iter;
LogEntry* prev = nullptr;
for (iter = entries.begin(); iter != entries.end(); ++iter) {
bits += iter->bitrate;
if (prev == nullptr) {
prev = &(*iter);
continue;
}
if (iter->time == prev->time) {
prev->bitrate = bits;
continue;
}
iter->total_streamed = prev->total_streamed + (iter->time - prev->time) / MS_PER_SEC * prev->bitrate;
iter->bitrate = bits;
merged.push_back(*prev);
prev = &(*iter);
}
prev->bitrate = bits;
merged.push_back(*prev);
return merged;
}
void read_entries(LogEntries& vec, std::size_t num) {
vec.reserve(num << 1);
long long tm;
int bit, dur;
while (num--) {
std::cin >> tm >> dur >> bit;
vec.push_back({tm, -bit, 0});
vec.push_back({tm - dur, bit, 0});
}
}
std::ostream &operator << (std::ostream& oss, const LogEntry& entry) {
return oss << "start=" << entry.time << ", bitrate(s)=" << entry.bitrate
<< ", streamed(kb)=" << std::setprecision(3) << std::fixed << entry.total_streamed;
}
template <typename T>
std::ostream &operator << (std::ostream& oss, const std::vector<T>& v) {
for (auto& item : v) {
oss << item << "\n";
}
return oss;
}
<commit_msg>Added some comments<commit_after>#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <iomanip>
#include <map>
struct LogEntry {
long long time;
int bitrate;
double total_streamed;
operator long long () const { return this->time; }
};
constexpr double MS_PER_SEC = 10 * 10 * 10;
using LogEntries = std::vector<LogEntry>;
void repl(const LogEntries&, std::size_t);
void read_entries(LogEntries&, std::size_t);
LogEntries reorder(LogEntries&);
#ifdef DEBUG
template <typename T>
std::ostream &operator << (std::ostream&, const std::vector<T>&);
std::ostream &operator << (std::ostream&, const LogEntry&);
#endif
int main() {
// Remove synchronization between cstdio and iostream
std::ios_base::sync_with_stdio(false);
// Prevent flushing of output stream before each io operation
std::cin.tie(nullptr);
LogEntries logEntries;
std::size_t logsize;
std::cin >> logsize;
read_entries(logEntries, logsize);
#ifdef DEBUG
std::cout << "\n" << logEntries << "\n\n";
#endif
logEntries = reorder(logEntries);
#ifdef DEBUG
std::cout << "Count: " << logEntries.size() << '\n';
std::cout << logEntries << "\n\n";
#endif
if (std::cin >> logsize) {
repl(logEntries, logsize);
}
return 0;
}
/**
* @brief Reads time ranges and sells lambourghinis'
* @details The repl stands for READ-EVALUATE-PRINT-LOOP.
* This method in particular will read any time range given, determine which log entries
* fall under this time range. It will then take the streams available under this
* time range and print what percentage of those streams were fully contained
* within the range given
*
* @param entries The collection of logs. This must have gone through the reorder
* function before it can be used here
* @param count The number of queries to expect
*/
void repl(const LogEntries& entries, std::size_t count) {
LogEntries::const_iterator hi, lo;
long long start, end;
double streamed;
std::cout.precision(3);
std::cout.setf(std::ios_base::fixed);
for (std::cin >> start >> end; count--; std::cin >> start >> end) {
lo = std::lower_bound(entries.begin(), entries.end(), start);
hi = std::upper_bound(lo, entries.end(), end);
if (hi == entries.end()) {
end = (hi - 1)->time;
}
#ifdef DEBUG
std::cout << lo->time << " <= " << start << "\n"
<< (hi == entries.end() ? hi - 1 : hi)->time << " >= " << end << std::endl;
#endif
streamed = (lo->time - start) / MS_PER_SEC * (lo == entries.begin() ? 0 : (lo - 1)->bitrate)
+ (hi - 1)->total_streamed - lo->total_streamed +
(end - (hi - 1)->time) / MS_PER_SEC * (hi - 1)->bitrate;
std::cout << streamed << '\n';
}
}
/**
* @brief Aranges the logs into non overlapping ranges for easier usage
* @details The logs are taken one by one and we cut them up into smaller
* logs which do not overlap. By doing this, it is easier to work with ranges
* because you don't have to worry about anything they overlap
*
* @param entries The initial entries we got as input
*/
LogEntries reorder(LogEntries &entries) {
std::sort(entries.begin(), entries.end(),
[](const LogEntry& lhs, const LogEntry& rhs) {
return lhs.time < rhs.time;
});
LogEntries merged;
int bits = 0;
LogEntries::iterator iter;
LogEntry* prev = nullptr;
for (iter = entries.begin(); iter != entries.end(); ++iter) {
bits += iter->bitrate;
if (prev == nullptr) {
prev = &(*iter);
continue;
}
if (iter->time == prev->time) {
prev->bitrate = bits;
continue;
}
iter->total_streamed = prev->total_streamed + (iter->time - prev->time) / MS_PER_SEC * prev->bitrate;
iter->bitrate = bits;
merged.push_back(*prev);
prev = &(*iter);
}
prev->bitrate = bits;
merged.push_back(*prev);
return merged;
}
/**
* @brief Reads the time ranges into the vector
*
* @param vec The vector to use for this
* @param num The number of items to read in
*/
void read_entries(LogEntries& vec, std::size_t num) {
vec.reserve(num << 1);
long long tm;
int bit, dur;
while (num--) {
std::cin >> tm >> dur >> bit;
vec.push_back({tm, -bit, 0});
vec.push_back({tm - dur, bit, 0});
}
}
std::ostream &operator << (std::ostream& oss, const LogEntry& entry) {
return oss << "start=" << entry.time << ", bitrate(s)=" << entry.bitrate
<< ", streamed(kb)=" << std::setprecision(3) << std::fixed << entry.total_streamed;
}
template <typename T>
std::ostream &operator << (std::ostream& oss, const std::vector<T>& v) {
for (auto& item : v) {
oss << item << "\n";
}
return oss;
}
<|endoftext|> |
<commit_before>#include "chatwindow.h"
#include "ui_chatwindow.h"
#include "QString"
#include "QColor"
#include "gui.h"
//
ChatWindow::ChatWindow(Gui* guiPointer) :
QMainWindow(nullptr),
ui(new Ui::ChatWindow)
{
ui->setupUi(this);
chatGui = guiPointer;
}
void ChatWindow::receiveMessage(const QString from, const QString to, const QString message, const QString time){
QString tempString = time;
ui->messageHistory->moveCursor(QTextCursor::End);
ui->messageHistory->setTextColor(Qt::black);
ui->messageHistory->insertPlainText(tempString.remove(0,11).remove(5,7)+" | ");
if(to == name){
ui->messageHistory->setTextColor(Qt::magenta);
ui->messageHistory->insertPlainText(from +" whispers to you: ");
ui->messageHistory->setTextColor(Qt::black);
}
else if (from == name && to != "root"){
ui->messageHistory->setTextColor(Qt::magenta);
ui->messageHistory->insertPlainText("You whisper to " + to + ": ");
ui->messageHistory->setTextColor(Qt::black);
}
else if (from == name && to == "root"){
ui->messageHistory->setTextColor(Qt::blue);
ui->messageHistory->insertPlainText("You say: ");
ui->messageHistory->setTextColor(Qt::black);
}
else {
ui->messageHistory->setTextColor(Qt::blue);
ui->messageHistory->insertPlainText(from + " says: ");
ui->messageHistory->setTextColor(Qt::black);
}
ui->messageHistory->insertPlainText(message);
ui->messageHistory->insertPlainText("\n");
if(ui->messageHistory->verticalScrollBar()->value() != ui->messageHistory->verticalScrollBar()->maximum())
{
}
else{
ui->messageHistory->verticalScrollBar()->setValue(ui->messageHistory->verticalScrollBar()->maximum());
}
}
void ChatWindow::setName(QString inName){
name = inName;
}
void ChatWindow::setServer(QString serverName){
server = serverName;
ui->roomTree->setHeaderLabel(server);
}
void ChatWindow::updateStruct(QVector<QString> treeStruct){
ui->roomTree->clear();
QTreeWidgetItem *treeParent;
treeParent=addRoot(treeStruct.at(0));
for (int i=1; i< treeStruct.size(); i++){
if (treeStruct.at(i)=="User"){
treeStruct.remove(i);
while (i < treeStruct.size()){
addLeaf(treeParent,treeStruct.at(i));
i++;
}
}
else {
treeParent=addSubRoot(treeParent,treeStruct.at(i));
}
}
}
QTreeWidgetItem* ChatWindow::addRoot(const QString rootName){
QTreeWidgetItem* item = new QTreeWidgetItem(ui->roomTree);
item->setText(0,rootName);
ui->roomTree->addTopLevelItem(item);
return item;
}
QTreeWidgetItem* ChatWindow::addSubRoot(QTreeWidgetItem *parent,const QString subRootName){
QTreeWidgetItem* item = new QTreeWidgetItem();
item->setText(0,subRootName);
parent->addChild(item);
return item;
}
void ChatWindow::addLeaf(QTreeWidgetItem *parent,const QString leafName){
QTreeWidgetItem* item = new QTreeWidgetItem();
item->setText(0,leafName);
parent->addChild(item);
}
ChatWindow::~ChatWindow()
{
delete ui;
}
//If sendbutton is pressed display sent from text and message in messagehistory
void ChatWindow::on_sendButton_clicked()
{
sendMessage();
ui->messageInput->clear();
receiver="root";
ui->sendButton->setText("Send");
//observera at root är en templösning
}
// send message on return
void ChatWindow::on_messageInput_returnPressed()
{
on_sendButton_clicked();
}
//whisper control
void ChatWindow::on_messageInput_textEdited(const QString &arg1)
{
QString to = arg1;
QString w = arg1;
QString whisper = arg1;
w.truncate(3);
whisper.truncate(9);
if(w == "/w " or w =="/W "){
to.remove("/w ",Qt::CaseInsensitive);
if(to.length() > 0 && to.endsWith(" ")){
to.chop(1);
receiver = to;
ui->sendButton->setText("To " + to);
ui->messageInput->clear();
}
}
if(whisper == "/whisper " or whisper =="/Whisper "){
to.remove("/whisper ",Qt::CaseInsensitive);
if(to.length() > 0 && to.endsWith(" ")){
to.chop(1);
receiver = to;
ui->sendButton->setText("To " + to);
ui->messageInput->clear();
}
}
// if(w=="/r " or w=="/R "){
}
void ChatWindow::sendMessage(){
chatGui->sendMessage(name,receiver,ui->messageInput->text());
}
void ChatWindow::on_actionBlack_triggered()
{
ui->messageInput->setStyleSheet("color: black;"
"background-color: grey;"
"selection-color: black;"
"selection-background-color: white");
ui->roomTree->setStyleSheet("color: black;"
"background-color: grey;"
"selection-color: black;"
"selection-background-color: white");
ui->messageHistory->setStyleSheet("color: black;"
"background-color: grey;"
"selection-color: black;"
"selection-background-color: white");
this->setStyleSheet("color: white;"
"background-color: black;"
"selection-color: black;"
"selection-background-color: white");
ui->mainToolBar->setStyleSheet("color: white;"
"background-color: black;"
"selection-color: black;"
"selection-background-color: white");
}
void ChatWindow::on_actionDefault_triggered()
{
ui->messageInput->setStyleSheet("");
ui->roomTree->setStyleSheet("");
ui->messageHistory->setStyleSheet("");
this->setStyleSheet("");
ui->mainToolBar->setStyleSheet("");
}
void ChatWindow::receiveHistory(QVector<QString> &historyVector){
for(int i = 0;i<historyVector.size(); i+=4){
QString tempString=historyVector.at(i+3);
ui->messageHistory->setTextColor(Qt::black);
ui->messageHistory->insertPlainText(tempString.remove(0,11).remove(5,7)+" | ");
ui->messageHistory->setTextColor(Qt::blue);
ui->messageHistory->insertPlainText(historyVector.at(i) + " says: ");
ui->messageHistory->setTextColor(Qt::black);
ui->messageHistory->insertPlainText(historyVector.at(i+2) + "\n");
}
}
void ChatWindow::on_actionChatty_triggered()
{
setStyleSheet("ChatWindow{border-image:url(:/files/icon/ChattY.png) 0 0 0 0 stretch stretch;}");
ui->menuBar->setStyleSheet("background-color: transparent;");
ui->statusBar->setStyleSheet("background-color: transparent;");
ui->centralWidget->setStyleSheet("background-color: transparent;");
ui->sendButton->setStyleSheet("background-color: none;");
}
void ChatWindow::on_actionCezch_triggered()
{
setStyleSheet("ChatWindow{background-color: qconicalgradient(cx:0.5, cy:0.5, angle:0, stop:0 rgba(255, 255, 255, 255), stop:0.373979 rgba(255, 255, 255, 255), stop:0.373991 rgba(33, 30, 255, 255), stop:0.624018 rgba(33, 30, 255, 255), stop:0.624043 rgba(255, 0, 0, 255), stop:1 rgba(255, 0, 0, 255));}");
ui->menuBar->setStyleSheet("background-color: transparent;");
ui->statusBar->setStyleSheet("background-color: transparent;");
ui->centralWidget->setStyleSheet("background-color: transparent;");
ui->sendButton->setStyleSheet("background-color: none;");
}
<commit_msg>Room tree will always expand when updated<commit_after>#include "chatwindow.h"
#include "ui_chatwindow.h"
#include "QString"
#include "QColor"
#include "gui.h"
//
ChatWindow::ChatWindow(Gui* guiPointer) :
QMainWindow(nullptr),
ui(new Ui::ChatWindow)
{
ui->setupUi(this);
chatGui = guiPointer;
}
void ChatWindow::receiveMessage(const QString from, const QString to, const QString message, const QString time){
QString tempString = time;
ui->messageHistory->moveCursor(QTextCursor::End);
ui->messageHistory->setTextColor(Qt::black);
ui->messageHistory->insertPlainText(tempString.remove(0,11).remove(5,7)+" | ");
if(to == name){
ui->messageHistory->setTextColor(Qt::magenta);
ui->messageHistory->insertPlainText(from +" whispers to you: ");
ui->messageHistory->setTextColor(Qt::black);
}
else if (from == name && to != "root"){
ui->messageHistory->setTextColor(Qt::magenta);
ui->messageHistory->insertPlainText("You whisper to " + to + ": ");
ui->messageHistory->setTextColor(Qt::black);
}
else if (from == name && to == "root"){
ui->messageHistory->setTextColor(Qt::blue);
ui->messageHistory->insertPlainText("You say: ");
ui->messageHistory->setTextColor(Qt::black);
}
else {
ui->messageHistory->setTextColor(Qt::blue);
ui->messageHistory->insertPlainText(from + " says: ");
ui->messageHistory->setTextColor(Qt::black);
}
ui->messageHistory->insertPlainText(message);
ui->messageHistory->insertPlainText("\n");
if(ui->messageHistory->verticalScrollBar()->value() != ui->messageHistory->verticalScrollBar()->maximum())
{
}
else{
ui->messageHistory->verticalScrollBar()->setValue(ui->messageHistory->verticalScrollBar()->maximum());
}
}
void ChatWindow::setName(QString inName){
name = inName;
}
void ChatWindow::setServer(QString serverName){
server = serverName;
ui->roomTree->setHeaderLabel(server);
}
void ChatWindow::updateStruct(QVector<QString> treeStruct){
ui->roomTree->clear();
QTreeWidgetItem *treeParent;
treeParent=addRoot(treeStruct.at(0));
for (int i=1; i< treeStruct.size(); i++){
if (treeStruct.at(i)=="User"){
treeStruct.remove(i);
while (i < treeStruct.size()){
addLeaf(treeParent,treeStruct.at(i));
i++;
}
}
else {
treeParent=addSubRoot(treeParent,treeStruct.at(i));
}
}
ui->roomTree->expandAll();
}
QTreeWidgetItem* ChatWindow::addRoot(const QString rootName){
QTreeWidgetItem* item = new QTreeWidgetItem(ui->roomTree);
item->setText(0,rootName);
ui->roomTree->addTopLevelItem(item);
return item;
}
QTreeWidgetItem* ChatWindow::addSubRoot(QTreeWidgetItem *parent,const QString subRootName){
QTreeWidgetItem* item = new QTreeWidgetItem();
item->setText(0,subRootName);
parent->addChild(item);
return item;
}
void ChatWindow::addLeaf(QTreeWidgetItem *parent,const QString leafName){
QTreeWidgetItem* item = new QTreeWidgetItem();
item->setText(0,leafName);
parent->addChild(item);
}
ChatWindow::~ChatWindow()
{
delete ui;
}
//If sendbutton is pressed display sent from text and message in messagehistory
void ChatWindow::on_sendButton_clicked()
{
sendMessage();
ui->messageInput->clear();
receiver="root";
ui->sendButton->setText("Send");
//observera at root är en templösning
}
// send message on return
void ChatWindow::on_messageInput_returnPressed()
{
on_sendButton_clicked();
}
//whisper control
void ChatWindow::on_messageInput_textEdited(const QString &arg1)
{
QString to = arg1;
QString w = arg1;
QString whisper = arg1;
w.truncate(3);
whisper.truncate(9);
if(w == "/w " or w =="/W "){
to.remove("/w ",Qt::CaseInsensitive);
if(to.length() > 0 && to.endsWith(" ")){
to.chop(1);
receiver = to;
ui->sendButton->setText("To " + to);
ui->messageInput->clear();
}
}
if(whisper == "/whisper " or whisper =="/Whisper "){
to.remove("/whisper ",Qt::CaseInsensitive);
if(to.length() > 0 && to.endsWith(" ")){
to.chop(1);
receiver = to;
ui->sendButton->setText("To " + to);
ui->messageInput->clear();
}
}
// if(w=="/r " or w=="/R "){
}
void ChatWindow::sendMessage(){
chatGui->sendMessage(name,receiver,ui->messageInput->text());
}
void ChatWindow::on_actionBlack_triggered()
{
ui->messageInput->setStyleSheet("color: black;"
"background-color: grey;"
"selection-color: black;"
"selection-background-color: white");
ui->roomTree->setStyleSheet("color: black;"
"background-color: grey;"
"selection-color: black;"
"selection-background-color: white");
ui->messageHistory->setStyleSheet("color: black;"
"background-color: grey;"
"selection-color: black;"
"selection-background-color: white");
this->setStyleSheet("color: white;"
"background-color: black;"
"selection-color: black;"
"selection-background-color: white");
ui->mainToolBar->setStyleSheet("color: white;"
"background-color: black;"
"selection-color: black;"
"selection-background-color: white");
}
void ChatWindow::on_actionDefault_triggered()
{
ui->messageInput->setStyleSheet("");
ui->roomTree->setStyleSheet("");
ui->messageHistory->setStyleSheet("");
this->setStyleSheet("");
ui->mainToolBar->setStyleSheet("");
}
void ChatWindow::receiveHistory(QVector<QString> &historyVector){
for(int i = 0;i<historyVector.size(); i+=4){
QString tempString=historyVector.at(i+3);
ui->messageHistory->setTextColor(Qt::black);
ui->messageHistory->insertPlainText(tempString.remove(0,11).remove(5,7)+" | ");
ui->messageHistory->setTextColor(Qt::blue);
ui->messageHistory->insertPlainText(historyVector.at(i) + " says: ");
ui->messageHistory->setTextColor(Qt::black);
ui->messageHistory->insertPlainText(historyVector.at(i+2) + "\n");
}
}
void ChatWindow::on_actionChatty_triggered()
{
setStyleSheet("ChatWindow{border-image:url(:/files/icon/ChattY.png) 0 0 0 0 stretch stretch;}");
ui->menuBar->setStyleSheet("background-color: transparent;");
ui->statusBar->setStyleSheet("background-color: transparent;");
ui->centralWidget->setStyleSheet("background-color: transparent;");
ui->sendButton->setStyleSheet("background-color: none;");
}
void ChatWindow::on_actionCezch_triggered()
{
setStyleSheet("ChatWindow{background-color: qconicalgradient(cx:0.5, cy:0.5, angle:0, stop:0 rgba(255, 255, 255, 255), stop:0.373979 rgba(255, 255, 255, 255), stop:0.373991 rgba(33, 30, 255, 255), stop:0.624018 rgba(33, 30, 255, 255), stop:0.624043 rgba(255, 0, 0, 255), stop:1 rgba(255, 0, 0, 255));}");
ui->menuBar->setStyleSheet("background-color: transparent;");
ui->statusBar->setStyleSheet("background-color: transparent;");
ui->centralWidget->setStyleSheet("background-color: transparent;");
ui->sendButton->setStyleSheet("background-color: none;");
}
<|endoftext|> |
<commit_before>/*
* At some point, the logger needs to have a better default location to put the files
* as well as being able to read a custom path from the .ini
*/
#include <fstream>
#include <string>
#include <map>
#include <memory>
#include <iostream>
#include "core/message.h"
#include "edict_messages.h"
#include "display_messages.h"
#include "lirch_plugin.h"
using namespace std;
void openLog(QString channel, map<QString, unique_ptr<ofstream>> &open_files);
void run(plugin_pipe pipe, std::string name)
{
bool shutdown = false;
pipe.write(registration_message::create(0, name, "display"));
pipe.write(registration_message::create(0, name, "me_display"));
map<QString, unique_ptr<ofstream>> open_files;
while(!shutdown)
{
message front = pipe.blocking_read();
if(front.type == "shutdown")
{
shutdown = true;
}
else if(front.type == "registration_status")
{
registration_status * internals=dynamic_cast<registration_status *>(front.getdata());
if (internals)
{
//This is a registration_status message, just like it said
if (!internals->status)
pipe.write(registration_message::create(internals->priority-1, name, internals->type));
}
}
else if (front.type == "display")
{
display_message * internals = dynamic_cast<display_message *>(front.getdata());
if(internals)
{
pipe.write(front.decrement_priority());
QString channelname = internals->channel;
if(!open_files.count(channelname))
openLog(channelname,open_files);
string nick(internals->nick.toUtf8().data());
string contents(internals->contents.toUtf8().data());
display_message_subtype::Enum subtype=internals->subtype;
string output ="";
if(subtype==display_message_subtype::NORMAL)
{
output = "<"+nick+"> "+contents+"\n";
}
else if(subtype==display_message_subtype::ME)
{
output = "* "+nick+" "+contents+"\n";
}
else if(subtype==display_message_subtype::NOTIFY)
{
string output = "#"+contents+"\n";
}
open_files[channelname]->write(output.c_str(), output.size());
}
}
else
{
pipe.write(front.decrement_priority());
}
}
//done_message::create(name);
}
void openLog(QString channel, map<QString, unique_ptr<ofstream>> &open_files)
{
string filename(channel.toUtf8().data());
filename += ".txt";
open_files[channel] = unique_ptr<ofstream>(new ofstream());
open_files[channel]->open(filename.c_str(), fstream::app);
open_files[channel]->write("~~~~~~~~\n", 9);
}
<commit_msg>made logger not search through the map so frequently when trying to open the file. discovered unique_ptr can't be stored in a map, and it only used to compile because of a gcc bug.<commit_after>/*
* At some point, the logger needs to have a better default location to put the files
* as well as being able to read a custom path from the .ini
*/
#include <fstream>
#include <string>
#include <map>
#include <memory>
#include <iostream>
#include "core/message.h"
#include "edict_messages.h"
#include "display_messages.h"
#include "lirch_plugin.h"
using namespace std;
void openLog(QString channel, map<QString, unique_ptr<ofstream>> &open_files);
void run(plugin_pipe pipe, std::string name)
{
bool shutdown = false;
pipe.write(registration_message::create(0, name, "display"));
pipe.write(registration_message::create(0, name, "me_display"));
map<QString, unique_ptr<ofstream>> open_files;
while(!shutdown)
{
message front = pipe.blocking_read();
if(front.type == "shutdown")
{
shutdown = true;
}
else if(front.type == "registration_status")
{
registration_status * internals=dynamic_cast<registration_status *>(front.getdata());
if (internals)
{
//This is a registration_status message, just like it said
if (!internals->status)
pipe.write(registration_message::create(internals->priority-1, name, internals->type));
}
}
else if (front.type == "display")
{
display_message * internals = dynamic_cast<display_message *>(front.getdata());
if(internals)
{
pipe.write(front.decrement_priority());
QString channelname = internals->channel;
if(!open_files.count(channelname))
openLog(channelname,open_files);
string nick(internals->nick.toUtf8().data());
string contents(internals->contents.toUtf8().data());
display_message_subtype::Enum subtype=internals->subtype;
string output ="";
if(subtype==display_message_subtype::NORMAL)
{
output = "<"+nick+"> "+contents+"\n";
}
else if(subtype==display_message_subtype::ME)
{
output = "* "+nick+" "+contents+"\n";
}
else if(subtype==display_message_subtype::NOTIFY)
{
output = "‼‽"+contents+"\n";
}
open_files[channelname]->write(output.c_str(), output.size());
}
}
else
{
pipe.write(front.decrement_priority());
}
}
//done_message::create(name);
}
void openLog(QString channel, map<QString, unique_ptr<ofstream>> &open_files)
{
string filename(channel.toUtf8().data());
filename += ".txt";
unique_ptr<ofstream> newFile = unique_ptr<ofstream>(new ofstream());
newFile->open(filename.c_str(), fstream::app);
*newFile <<"~~~~~~~~"<<endl;
open_files[channel]=newFile;
}
<|endoftext|> |
<commit_before>/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: SwXFilterOptions.cxx,v $
*
* $Revision: 1.9 $
*
* last change: $Author: obo $ $Date: 2006-09-16 23:27:51 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"
#ifndef _SWXFILTEROPTIONS_HXX
#include <SwXFilterOptions.hxx>
#endif
#ifndef _SHELLIO_HXX
#include <shellio.hxx>
#endif
#ifndef SW_SWDLL_HXX
#include <swdll.hxx>
#endif
#ifndef _UNOPRNMS_HXX
#include <unoprnms.hxx>
#endif
//CHINA001 #ifndef _ASCFLDLG_HXX
//CHINA001 #include <ascfldlg.hxx>
//CHINA001 #endif
#ifndef _VOS_MUTEX_HXX_ //autogen
#include <vos/mutex.hxx>
#endif
#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif
#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
#include <com/sun/star/lang/XUnoTunnel.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_EXECUTABLEDIALOGRESULTS_HPP_
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
#endif
#ifndef _UNTOOLS_UCBSTREAMHELPER_HXX
#include <unotools/ucbstreamhelper.hxx>
#endif
#ifndef _UNOTXDOC_HXX //autogen
#include <unotxdoc.hxx>
#endif
#include "swabstdlg.hxx" //CHINA001
#include "dialog.hrc" //CHINA001
using namespace ::com::sun::star;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::com::sun::star::document;
using namespace ::com::sun::star::lang;
#define SWFILTEROPTIONSOBJ_SERVICE RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ui.dialogs.FilterOptionsDialog")
#define SWFILTEROPTIONSOBJ_IMPLNAME RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.FilterOptionsDialog")
#define FILTER_OPTIONS_NAME RTL_CONSTASCII_USTRINGPARAM("FilterOptions")
/*-- 2002/06/21 11:01:23---------------------------------------------------
-----------------------------------------------------------------------*/
SwXFilterOptions::SwXFilterOptions() :
bExport( sal_False )
{
}
/*-- 2002/06/21 11:01:24---------------------------------------------------
-----------------------------------------------------------------------*/
SwXFilterOptions::~SwXFilterOptions()
{
}
/*-- 2002/06/21 11:01:24---------------------------------------------------
-----------------------------------------------------------------------*/
::rtl::OUString SwXFilterOptions::getImplementationName_Static()
{
return ::rtl::OUString(SWFILTEROPTIONSOBJ_IMPLNAME);
}
/*-- 2002/06/21 11:01:24---------------------------------------------------
-----------------------------------------------------------------------*/
uno::Sequence< ::rtl::OUString> SwXFilterOptions::getSupportedServiceNames_Static()
{
::rtl::OUString sService(SWFILTEROPTIONSOBJ_SERVICE);
return uno::Sequence< ::rtl::OUString> (&sService, 1);
}
/*-- 2002/06/21 11:01:25---------------------------------------------------
-----------------------------------------------------------------------*/
uno::Sequence< beans::PropertyValue > SwXFilterOptions::getPropertyValues() throw (uno::RuntimeException)
{
uno::Sequence<beans::PropertyValue> aRet(1);
beans::PropertyValue* pArray = aRet.getArray();
pArray[0].Name = rtl::OUString( FILTER_OPTIONS_NAME );
pArray[0].Value <<= sFilterOptions;
return aRet;
}
/*-- 2002/06/21 11:01:25---------------------------------------------------
-----------------------------------------------------------------------*/
void SwXFilterOptions::setPropertyValues( const uno::Sequence<beans::PropertyValue >& aProps )
throw (beans::UnknownPropertyException, beans::PropertyVetoException,
IllegalArgumentException, WrappedTargetException, uno::RuntimeException)
{
const beans::PropertyValue* pPropArray = aProps.getConstArray();
long nPropCount = aProps.getLength();
for (long i = 0; i < nPropCount; i++)
{
const beans::PropertyValue& rProp = pPropArray[i];
::rtl::OUString aPropName = rProp.Name;
if ( aPropName.equalsAscii( SW_PROP_NAME_STR(UNO_NAME_FILTER_NAME) ) )
rProp.Value >>= sFilterName;
else if ( aPropName == ::rtl::OUString(FILTER_OPTIONS_NAME) )
rProp.Value >>= sFilterOptions;
else if ( aPropName.equalsAscii( "InputStream" ) )
rProp.Value >>= xInputStream;
}
}
/*-- 2002/06/21 11:01:25---------------------------------------------------
-----------------------------------------------------------------------*/
void SwXFilterOptions::setTitle( const ::rtl::OUString& aTitle )
throw (uno::RuntimeException)
{
}
/*-- 2002/06/21 11:01:25---------------------------------------------------
-----------------------------------------------------------------------*/
sal_Int16 SwXFilterOptions::execute() throw (uno::RuntimeException)
{
sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
SvStream* pInStream = NULL;
if ( xInputStream.is() )
pInStream = utl::UcbStreamHelper::CreateStream( xInputStream );
uno::Reference< XUnoTunnel > xTunnel(xModel, uno::UNO_QUERY);
SwDocShell* pDocShell = 0;
if(xTunnel.is())
{
SwXTextDocument* pXDoc = (SwXTextDocument*)xTunnel->getSomething(SwXTextDocument::getUnoTunnelId());
pDocShell = pXDoc ? pXDoc->GetDocShell() : 0;
}
if(pDocShell)
{
//CHINA001 SwAsciiFilterDlg aAsciiDlg( NULL, *pDocShell, pInStream );
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();//CHINA001
DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");//CHINA001
AbstractSwAsciiFilterDlg* pAsciiDlg = pFact->CreateSwAsciiFilterDlg( NULL, *pDocShell,pInStream, ResId( DLG_ASCII_FILTER ));
DBG_ASSERT(pAsciiDlg, "Dialogdiet fail!");//CHINA001
if(RET_OK == pAsciiDlg->Execute()) //CHINA001 if(RET_OK == aAsciiDlg.Execute())
{
SwAsciiOptions aOptions;
pAsciiDlg->FillOptions( aOptions );//CHINA001 aAsciiDlg.FillOptions( aOptions );
String sTmp;
aOptions.WriteUserData(sTmp);
sFilterOptions = sTmp;
nRet = ui::dialogs::ExecutableDialogResults::OK;
}
delete pAsciiDlg;
}
if( pInStream )
delete pInStream;
return nRet;
}
/*-- 2002/06/21 11:01:26---------------------------------------------------
-----------------------------------------------------------------------*/
void SwXFilterOptions::setTargetDocument( const uno::Reference< XComponent >& xDoc )
throw (IllegalArgumentException, uno::RuntimeException)
{
bExport = sal_False;
xModel = xDoc;
}
/*-- 2002/06/21 11:01:26---------------------------------------------------
-----------------------------------------------------------------------*/
void SwXFilterOptions::setSourceDocument( const uno::Reference<XComponent >& xDoc )
throw (IllegalArgumentException,uno::RuntimeException)
{
bExport = sal_True;
xModel = xDoc;
}
/*-- 2002/06/21 11:01:26---------------------------------------------------
-----------------------------------------------------------------------*/
::rtl::OUString SwXFilterOptions::getImplementationName() throw(uno::RuntimeException)
{
return ::rtl::OUString(SWFILTEROPTIONSOBJ_IMPLNAME);
}
/*-- 2002/06/21 11:01:27---------------------------------------------------
-----------------------------------------------------------------------*/
sal_Bool SwXFilterOptions::supportsService( const ::rtl::OUString& rServiceName )
throw(uno::RuntimeException)
{
return rServiceName == ::rtl::OUString(SWFILTEROPTIONSOBJ_SERVICE);
}
/*-- 2002/06/21 11:01:28---------------------------------------------------
-----------------------------------------------------------------------*/
uno::Sequence< ::rtl::OUString > SwXFilterOptions::getSupportedServiceNames()
throw(uno::RuntimeException)
{
return SwXFilterOptions::getSupportedServiceNames_Static();
}
uno::Reference<uno::XInterface> SAL_CALL SwXFilterOptions_createInstance(
const uno::Reference<lang::XMultiServiceFactory>& )
{
::vos::OGuard aGuard(Application::GetSolarMutex());
SwDLL::Init();
return (::cppu::OWeakObject*) new SwXFilterOptions;
}
<commit_msg>INTEGRATION: CWS residcleanup (1.9.240); FILE MERGED 2007/03/04 17:03:11 pl 1.9.240.1: #i73635# ResId cleanup<commit_after>/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: SwXFilterOptions.cxx,v $
*
* $Revision: 1.10 $
*
* last change: $Author: rt $ $Date: 2007-04-26 09:22:33 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"
#ifndef _SWXFILTEROPTIONS_HXX
#include <SwXFilterOptions.hxx>
#endif
#ifndef _SHELLIO_HXX
#include <shellio.hxx>
#endif
#ifndef SW_SWDLL_HXX
#include <swdll.hxx>
#endif
#ifndef _UNOPRNMS_HXX
#include <unoprnms.hxx>
#endif
//CHINA001 #ifndef _ASCFLDLG_HXX
//CHINA001 #include <ascfldlg.hxx>
//CHINA001 #endif
#ifndef _VOS_MUTEX_HXX_ //autogen
#include <vos/mutex.hxx>
#endif
#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif
#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
#include <com/sun/star/lang/XUnoTunnel.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_EXECUTABLEDIALOGRESULTS_HPP_
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
#endif
#ifndef _UNTOOLS_UCBSTREAMHELPER_HXX
#include <unotools/ucbstreamhelper.hxx>
#endif
#ifndef _UNOTXDOC_HXX //autogen
#include <unotxdoc.hxx>
#endif
#include "swabstdlg.hxx" //CHINA001
#include "dialog.hrc" //CHINA001
using namespace ::com::sun::star;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::com::sun::star::document;
using namespace ::com::sun::star::lang;
#define SWFILTEROPTIONSOBJ_SERVICE RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ui.dialogs.FilterOptionsDialog")
#define SWFILTEROPTIONSOBJ_IMPLNAME RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.FilterOptionsDialog")
#define FILTER_OPTIONS_NAME RTL_CONSTASCII_USTRINGPARAM("FilterOptions")
/*-- 2002/06/21 11:01:23---------------------------------------------------
-----------------------------------------------------------------------*/
SwXFilterOptions::SwXFilterOptions() :
bExport( sal_False )
{
}
/*-- 2002/06/21 11:01:24---------------------------------------------------
-----------------------------------------------------------------------*/
SwXFilterOptions::~SwXFilterOptions()
{
}
/*-- 2002/06/21 11:01:24---------------------------------------------------
-----------------------------------------------------------------------*/
::rtl::OUString SwXFilterOptions::getImplementationName_Static()
{
return ::rtl::OUString(SWFILTEROPTIONSOBJ_IMPLNAME);
}
/*-- 2002/06/21 11:01:24---------------------------------------------------
-----------------------------------------------------------------------*/
uno::Sequence< ::rtl::OUString> SwXFilterOptions::getSupportedServiceNames_Static()
{
::rtl::OUString sService(SWFILTEROPTIONSOBJ_SERVICE);
return uno::Sequence< ::rtl::OUString> (&sService, 1);
}
/*-- 2002/06/21 11:01:25---------------------------------------------------
-----------------------------------------------------------------------*/
uno::Sequence< beans::PropertyValue > SwXFilterOptions::getPropertyValues() throw (uno::RuntimeException)
{
uno::Sequence<beans::PropertyValue> aRet(1);
beans::PropertyValue* pArray = aRet.getArray();
pArray[0].Name = rtl::OUString( FILTER_OPTIONS_NAME );
pArray[0].Value <<= sFilterOptions;
return aRet;
}
/*-- 2002/06/21 11:01:25---------------------------------------------------
-----------------------------------------------------------------------*/
void SwXFilterOptions::setPropertyValues( const uno::Sequence<beans::PropertyValue >& aProps )
throw (beans::UnknownPropertyException, beans::PropertyVetoException,
IllegalArgumentException, WrappedTargetException, uno::RuntimeException)
{
const beans::PropertyValue* pPropArray = aProps.getConstArray();
long nPropCount = aProps.getLength();
for (long i = 0; i < nPropCount; i++)
{
const beans::PropertyValue& rProp = pPropArray[i];
::rtl::OUString aPropName = rProp.Name;
if ( aPropName.equalsAscii( SW_PROP_NAME_STR(UNO_NAME_FILTER_NAME) ) )
rProp.Value >>= sFilterName;
else if ( aPropName == ::rtl::OUString(FILTER_OPTIONS_NAME) )
rProp.Value >>= sFilterOptions;
else if ( aPropName.equalsAscii( "InputStream" ) )
rProp.Value >>= xInputStream;
}
}
/*-- 2002/06/21 11:01:25---------------------------------------------------
-----------------------------------------------------------------------*/
void SwXFilterOptions::setTitle( const ::rtl::OUString& aTitle )
throw (uno::RuntimeException)
{
}
/*-- 2002/06/21 11:01:25---------------------------------------------------
-----------------------------------------------------------------------*/
sal_Int16 SwXFilterOptions::execute() throw (uno::RuntimeException)
{
sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
SvStream* pInStream = NULL;
if ( xInputStream.is() )
pInStream = utl::UcbStreamHelper::CreateStream( xInputStream );
uno::Reference< XUnoTunnel > xTunnel(xModel, uno::UNO_QUERY);
SwDocShell* pDocShell = 0;
if(xTunnel.is())
{
SwXTextDocument* pXDoc = (SwXTextDocument*)xTunnel->getSomething(SwXTextDocument::getUnoTunnelId());
pDocShell = pXDoc ? pXDoc->GetDocShell() : 0;
}
if(pDocShell)
{
//CHINA001 SwAsciiFilterDlg aAsciiDlg( NULL, *pDocShell, pInStream );
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();//CHINA001
DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");//CHINA001
AbstractSwAsciiFilterDlg* pAsciiDlg = pFact->CreateSwAsciiFilterDlg( NULL, *pDocShell,pInStream, DLG_ASCII_FILTER );
DBG_ASSERT(pAsciiDlg, "Dialogdiet fail!");//CHINA001
if(RET_OK == pAsciiDlg->Execute()) //CHINA001 if(RET_OK == aAsciiDlg.Execute())
{
SwAsciiOptions aOptions;
pAsciiDlg->FillOptions( aOptions );//CHINA001 aAsciiDlg.FillOptions( aOptions );
String sTmp;
aOptions.WriteUserData(sTmp);
sFilterOptions = sTmp;
nRet = ui::dialogs::ExecutableDialogResults::OK;
}
delete pAsciiDlg;
}
if( pInStream )
delete pInStream;
return nRet;
}
/*-- 2002/06/21 11:01:26---------------------------------------------------
-----------------------------------------------------------------------*/
void SwXFilterOptions::setTargetDocument( const uno::Reference< XComponent >& xDoc )
throw (IllegalArgumentException, uno::RuntimeException)
{
bExport = sal_False;
xModel = xDoc;
}
/*-- 2002/06/21 11:01:26---------------------------------------------------
-----------------------------------------------------------------------*/
void SwXFilterOptions::setSourceDocument( const uno::Reference<XComponent >& xDoc )
throw (IllegalArgumentException,uno::RuntimeException)
{
bExport = sal_True;
xModel = xDoc;
}
/*-- 2002/06/21 11:01:26---------------------------------------------------
-----------------------------------------------------------------------*/
::rtl::OUString SwXFilterOptions::getImplementationName() throw(uno::RuntimeException)
{
return ::rtl::OUString(SWFILTEROPTIONSOBJ_IMPLNAME);
}
/*-- 2002/06/21 11:01:27---------------------------------------------------
-----------------------------------------------------------------------*/
sal_Bool SwXFilterOptions::supportsService( const ::rtl::OUString& rServiceName )
throw(uno::RuntimeException)
{
return rServiceName == ::rtl::OUString(SWFILTEROPTIONSOBJ_SERVICE);
}
/*-- 2002/06/21 11:01:28---------------------------------------------------
-----------------------------------------------------------------------*/
uno::Sequence< ::rtl::OUString > SwXFilterOptions::getSupportedServiceNames()
throw(uno::RuntimeException)
{
return SwXFilterOptions::getSupportedServiceNames_Static();
}
uno::Reference<uno::XInterface> SAL_CALL SwXFilterOptions_createInstance(
const uno::Reference<lang::XMultiServiceFactory>& )
{
::vos::OGuard aGuard(Application::GetSolarMutex());
SwDLL::Init();
return (::cppu::OWeakObject*) new SwXFilterOptions;
}
<|endoftext|> |
<commit_before>#include "InstructionParser.hpp"
#include <iostream>
#include <vector>
#include <utility>
#include <regex>
#include "boost/tokenizer.hpp"
#include "boost/range/algorithm.hpp"
Tokens InstructionParser::parseInstructions(const std::string& instructions)
{
boost::tokenizer<boost::char_separator<char>> instructionTokenizer{instructions, boost::char_separator<char>{"\n, "}};
Tokens tokens;
for (const auto&token : instructionTokenizer)
{
boost::copy( parseInstruction(token), std::back_inserter(tokens));
}
return tokens;
}
Tokens InstructionParser::parseInstruction(const std::string& instruction)
{
const auto trimmedInstruction = trimWhitespacesOnFront(instruction);
if (trimmedInstruction.empty())
{
return{};
}
using TextToTokens = std::vector<std::pair<std::regex, TokenType>>;
const TextToTokens acceptableInstructions{{std::regex{"out"}, TokenType::Out},
{std::regex{"\\(0\\)"}, TokenType::ZeroWithBrackets},
{std::regex{"ld"}, TokenType::Ld},
{std::regex{"a"}, TokenType::A},
{std::regex{"0"}, TokenType::Number8Bit}};
const auto noArgumentInstructionPosition = std::find_if(acceptableInstructions.begin(), acceptableInstructions.end(), [&](const auto& tokenMap)
{
return std::regex_match(trimmedInstruction, tokenMap.first);
});
if (noArgumentInstructionPosition != acceptableInstructions.end())
{
return {noArgumentInstructionPosition->second};
}
throw UnknownInstruction{"Unknown instruction: " + instruction};
}
std::string InstructionParser::trimWhitespacesOnFront(const std::string& instruction)
{
const auto firstRelevantCharPosition = instruction.find_first_not_of(" \t");
if (firstRelevantCharPosition != std::string::npos)
{
return instruction.substr(firstRelevantCharPosition);
}
return {};
}<commit_msg>InstructionParser is able to accept 255 as token<commit_after>#include "InstructionParser.hpp"
#include <iostream>
#include <vector>
#include <utility>
#include <regex>
#include "boost/tokenizer.hpp"
#include "boost/range/algorithm.hpp"
Tokens InstructionParser::parseInstructions(const std::string& instructions)
{
boost::tokenizer<boost::char_separator<char>> instructionTokenizer{instructions, boost::char_separator<char>{"\n, "}};
Tokens tokens;
for (const auto&token : instructionTokenizer)
{
boost::copy( parseInstruction(token), std::back_inserter(tokens));
}
return tokens;
}
Tokens InstructionParser::parseInstruction(const std::string& instruction)
{
const auto trimmedInstruction = trimWhitespacesOnFront(instruction);
if (trimmedInstruction.empty())
{
return{};
}
using TextToTokens = std::vector<std::pair<std::regex, TokenType>>;
const TextToTokens acceptableInstructions{{std::regex{"out"}, TokenType::Out},
{std::regex{"\\(0\\)"}, TokenType::ZeroWithBrackets},
{std::regex{"ld"}, TokenType::Ld},
{std::regex{"a"}, TokenType::A},
{std::regex{"0"}, TokenType::Number8Bit},
{std::regex{"255"}, TokenType::Number8Bit}};
const auto noArgumentInstructionPosition = std::find_if(acceptableInstructions.begin(), acceptableInstructions.end(), [&](const auto& tokenMap)
{
return std::regex_match(trimmedInstruction, tokenMap.first);
});
if (noArgumentInstructionPosition != acceptableInstructions.end())
{
return {noArgumentInstructionPosition->second};
}
throw UnknownInstruction{"Unknown instruction: " + instruction};
}
std::string InstructionParser::trimWhitespacesOnFront(const std::string& instruction)
{
const auto firstRelevantCharPosition = instruction.find_first_not_of(" \t");
if (firstRelevantCharPosition != std::string::npos)
{
return instruction.substr(firstRelevantCharPosition);
}
return {};
}<|endoftext|> |
<commit_before>/*************************************************************************
*
* $RCSfile: fmtline.hxx,v $
*
* $Revision: 1.5 $
*
* last change: $Author: hr $ $Date: 2003-07-16 18:06:05 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef SW_FMTLINE_HXX
#define SW_FMTLINE_HXX
#ifndef _SFXPOOLITEM_HXX //autogen
#include <svtools/poolitem.hxx>
#endif
#ifndef _HINTIDS_HXX
#include <hintids.hxx>
#endif
#ifndef _FORMAT_HXX //autogen
#include <format.hxx>
#endif
class IntlWrapper;
class SwFmtLineNumber: public SfxPoolItem
{
ULONG nStartValue :24; //Startwert fuer den Absatz, 0 == kein Startwert
ULONG bCountLines :1; //Zeilen des Absatzes sollen mitgezaehlt werden.
public:
SwFmtLineNumber();
~SwFmtLineNumber();
TYPEINFO();
// "pure virtual Methoden" vom SfxPoolItem
virtual int operator==( const SfxPoolItem& ) const;
virtual SfxPoolItem* Clone( SfxItemPool* pPool = 0 ) const;
virtual SfxPoolItem* Create(SvStream &, USHORT nVer) const;
virtual SvStream& Store(SvStream &, USHORT nIVer) const;
virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePres,
SfxMapUnit eCoreMetric,
SfxMapUnit ePresMetric,
String &rText,
const IntlWrapper* pIntl = 0 ) const;
virtual USHORT GetVersion( USHORT nFFVer ) const;
virtual BOOL QueryValue( com::sun::star::uno::Any& rVal, BYTE nMemberId = 0 ) const;
virtual BOOL PutValue( const com::sun::star::uno::Any& rVal, BYTE nMemberId = 0 );
ULONG GetStartValue() const { return nStartValue; }
BOOL IsCount() const { return bCountLines != 0; }
void SetStartValue( ULONG nNew ) { nStartValue = nNew; }
void SetCountLines( BOOL b ) { bCountLines = b; }
};
#if !(defined(MACOSX) && ( __GNUC__ < 3 ))
// GrP moved to gcc_outl.cxx; revisit with gcc3
inline const SwFmtLineNumber &SwAttrSet::GetLineNumber(BOOL bInP) const
{ return (const SwFmtLineNumber&)Get( RES_LINENUMBER,bInP); }
inline const SwFmtLineNumber &SwFmt::GetLineNumber(BOOL bInP) const
{ return aSet.GetLineNumber(bInP); }
#endif
#endif
<commit_msg>INTEGRATION: CWS geordi2q14 (1.5.274); FILE MERGED 2004/01/30 14:26:14 hr 1.5.274.1: #111934#: merge CWS ooo111fix2<commit_after>/*************************************************************************
*
* $RCSfile: fmtline.hxx,v $
*
* $Revision: 1.6 $
*
* last change: $Author: hr $ $Date: 2004-02-02 17:57:48 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef SW_FMTLINE_HXX
#define SW_FMTLINE_HXX
#ifndef _SFXPOOLITEM_HXX //autogen
#include <svtools/poolitem.hxx>
#endif
#ifndef _HINTIDS_HXX
#include <hintids.hxx>
#endif
#ifndef _FORMAT_HXX //autogen
#include <format.hxx>
#endif
class IntlWrapper;
class SwFmtLineNumber: public SfxPoolItem
{
ULONG nStartValue :24; //Startwert fuer den Absatz, 0 == kein Startwert
ULONG bCountLines :1; //Zeilen des Absatzes sollen mitgezaehlt werden.
public:
SwFmtLineNumber();
~SwFmtLineNumber();
TYPEINFO();
// "pure virtual Methoden" vom SfxPoolItem
virtual int operator==( const SfxPoolItem& ) const;
virtual SfxPoolItem* Clone( SfxItemPool* pPool = 0 ) const;
virtual SfxPoolItem* Create(SvStream &, USHORT nVer) const;
virtual SvStream& Store(SvStream &, USHORT nIVer) const;
virtual SfxItemPresentation GetPresentation( SfxItemPresentation ePres,
SfxMapUnit eCoreMetric,
SfxMapUnit ePresMetric,
String &rText,
const IntlWrapper* pIntl = 0 ) const;
virtual USHORT GetVersion( USHORT nFFVer ) const;
virtual BOOL QueryValue( com::sun::star::uno::Any& rVal, BYTE nMemberId = 0 ) const;
virtual BOOL PutValue( const com::sun::star::uno::Any& rVal, BYTE nMemberId = 0 );
ULONG GetStartValue() const { return nStartValue; }
BOOL IsCount() const { return bCountLines != 0; }
void SetStartValue( ULONG nNew ) { nStartValue = nNew; }
void SetCountLines( BOOL b ) { bCountLines = b; }
};
inline const SwFmtLineNumber &SwAttrSet::GetLineNumber(BOOL bInP) const
{ return (const SwFmtLineNumber&)Get( RES_LINENUMBER,bInP); }
inline const SwFmtLineNumber &SwFmt::GetLineNumber(BOOL bInP) const
{ return aSet.GetLineNumber(bInP); }
#endif
<|endoftext|> |
<commit_before>/*************************************************************************
*
* $RCSfile: numrule.hxx,v $
*
* $Revision: 1.23 $
*
* last change: $Author: vg $ $Date: 2005-02-22 10:02:30 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef _NUMRULE_HXX
#define _NUMRULE_HXX
#ifndef _LINK_HXX //autogen
#include <tools/link.hxx>
#endif
#ifndef _SV_GEN_HXX //autogen wg. Size
#include <tools/gen.hxx>
#endif
#ifndef _STRING_HXX //autogen
#include <tools/string.hxx>
#endif
#ifndef _SVX_SVXENUM_HXX //autogen
#include <svx/svxenum.hxx>
#endif
#ifndef _SVX_NUMITEM_HXX
#include <svx/numitem.hxx>
#endif
#ifndef INCLUDED_SWDLLAPI_H
#include "swdllapi.h"
#endif
#ifndef _SWTYPES_HXX
#include <swtypes.hxx>
#endif
#ifndef _CALBCK_HXX
#include <calbck.hxx>
#endif
#ifndef _ERRHDL_HXX
#include <errhdl.hxx> // Fuer die inline-ASSERTs
#endif
#ifndef _SWERROR_H
#include <error.h> // Fuer die inline-ASSERTs
#endif
#ifndef _SW_BIT_ARRAY_HXX
#include <SwBitArray.hxx> // #i27615#
#endif
#ifndef _HINTS_HXX
#include <hints.hxx>
#endif
#include <hash_map>
#include <stringhash.hxx>
class Font;
class SvxBrushItem;
class SvxNumRule;
class SwCharFmt;
class SwDoc;
class SwFmtVertOrient;
class SwNodeNum;
class SwTxtNode;
extern char __FAR_DATA sOutlineStr[]; // SWG-Filter
BYTE SW_DLLPUBLIC GetRealLevel( const BYTE nLvl );
BOOL SW_DLLPUBLIC IsNum( BYTE nLvl );
BOOL SW_DLLPUBLIC IsShowNum( BYTE nLvl );
void SW_DLLPUBLIC SetNoNum( BYTE * nLvl, BOOL nVal = TRUE );
void SW_DLLPUBLIC SetLevel( BYTE * nLvl, BYTE nNewLvl);
const sal_Unicode cBulletChar = 0x2022; // Charakter fuer Aufzaehlungen
class SW_DLLPUBLIC SwNumFmt : public SvxNumberFormat, public SwClient
{
SwFmtVertOrient* pVertOrient;
SW_DLLPRIVATE void UpdateNumNodes( SwDoc* pDoc );
SW_DLLPRIVATE virtual void NotifyGraphicArrived();
public:
SwNumFmt();
SwNumFmt( const SwNumFmt& );
SwNumFmt( const SvxNumberFormat&, SwDoc* pDoc);
virtual ~SwNumFmt();
SwNumFmt& operator=( const SwNumFmt& );
BOOL operator==( const SwNumFmt& ) const;
BOOL operator!=( const SwNumFmt& r ) const { return !(*this == r); }
const Graphic* GetGraphic() const;
SwCharFmt* GetCharFmt() const { return (SwCharFmt*)pRegisteredIn; }
void SetCharFmt( SwCharFmt* );
virtual void Modify( SfxPoolItem* pOld, SfxPoolItem* pNew );
virtual void SetCharFmtName(const String& rSet);
virtual const String& GetCharFmtName()const;
virtual void SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize = 0, const SvxFrameVertOrient* pOrient = 0);
virtual void SetVertOrient(SvxFrameVertOrient eSet);
virtual SvxFrameVertOrient GetVertOrient() const;
const SwFmtVertOrient* GetGraphicOrientation() const;
BOOL IsEnumeration() const; // #i22362#
BOOL IsItemize() const; // #i29560#
};
enum SwNumRuleType { OUTLINE_RULE = 0, NUM_RULE = 1, RULE_END = 2 };
class SW_DLLPUBLIC SwNumRule
{
friend void _FinitCore();
static SwNumFmt* aBaseFmts [ RULE_END ][ MAXLEVEL ];
static USHORT aDefNumIndents[ MAXLEVEL ];
static USHORT nRefCount;
static Font* pDefBulletFont;
static char* pDefOutlineName;
SwNumFmt* aFmts[ MAXLEVEL ];
/**
cache for associated text nodes
*/
SwTxtNodeTable * pList;
/**
marked levels
*/
SwBitArray aMarkedLevels;
// #i36749#
/**
hash_map containing "name->rule" relation
*/
std::hash_map<String, SwNumRule *, StringHash> * pNumRuleMap;
String sName;
SwNumRuleType eRuleType;
USHORT nPoolFmtId; // Id-fuer "automatich" erzeugte NumRules
USHORT nPoolHelpId; // HelpId fuer diese Pool-Vorlage
BYTE nPoolHlpFileId; // FilePos ans Doc auf die Vorlagen-Hilfen
BOOL bAutoRuleFlag : 1;
BOOL bInvalidRuleFlag : 1;
BOOL bContinusNum : 1; // Fortlaufende Numerierung - ohne Ebenen
BOOL bAbsSpaces : 1; // die Ebenen repraesentieren absol. Einzuege
SW_DLLPRIVATE static void _MakeDefBulletFont();
// forbidden and not implemented.
SwNumRule();
public:
// single argument constructors shall be explicit.
explicit SwNumRule( const String& rNm, SwNumRuleType = NUM_RULE,
BOOL bAutoFlg = TRUE );
SwNumRule( const SwNumRule& );
~SwNumRule();
SwNumRule& operator=( const SwNumRule& );
BOOL operator==( const SwNumRule& ) const;
BOOL operator!=( const SwNumRule& r ) const { return !(*this == r); }
const SwNumFmt* GetNumFmt( USHORT i ) const;
const SwNumFmt& Get( USHORT i ) const;
void Set( USHORT i, const SwNumFmt* );
void Set( USHORT i, const SwNumFmt& );
String MakeNumString( const SwNodeNum&, BOOL bInclStrings = TRUE,
BOOL bOnlyArabic = FALSE ) const;
/**
Returns list of associated text nodes.
@return list of associated text nodes, or NULL if none present
*/
const SwTxtNodeTable * GetList() const { return pList; }
/**
Set list of associated text nodes.
@param _pList the list of associated text nodes
*/
void SetList(SwTxtNodeTable * _pList);
// #i36749#
/**
Register this rule in a "name->numrule" map.
@param pNumRuleMap map to register in
*/
void SetNumRuleMap(std::hash_map<String, SwNumRule *, StringHash> *
pNumRuleMap);
static const Font& GetDefBulletFont();
static char* GetOutlineRuleName() { return pDefOutlineName; }
static USHORT GetNumIndent( BYTE nLvl );
static USHORT GetBullIndent( BYTE nLvl );
SwNumRuleType GetRuleType() const { return eRuleType; }
void SetRuleType( SwNumRuleType eNew ) { eRuleType = eNew;
bInvalidRuleFlag = TRUE; }
// eine Art Copy-Constructor, damit die Num-Formate auch an den
// richtigen CharFormaten eines Dokumentes haengen !!
// (Kopiert die NumFormate und returnt sich selbst)
SwNumRule& CopyNumRule( SwDoc*, const SwNumRule& );
// testet ob die CharFormate aus dem angegeben Doc sind und kopiert
// die gegebenfalls
void CheckCharFmts( SwDoc* pDoc );
#ifndef NUM_RELSPACE
// test ob der Einzug von dieser Numerierung kommt.
BOOL IsRuleLSpace( SwTxtNode& rNd ) const;
#endif
const String& GetName() const { return sName; }
void SetName( const String& rNm ); // #i36749#
BOOL IsAutoRule() const { return bAutoRuleFlag; }
void SetAutoRule( BOOL bFlag ) { bAutoRuleFlag = bFlag; }
BOOL IsInvalidRule() const { return bInvalidRuleFlag; }
void SetInvalidRule( BOOL bFlag );
BOOL IsContinusNum() const { return bContinusNum; }
void SetContinusNum( BOOL bFlag ) { bContinusNum = bFlag; }
BOOL IsAbsSpaces() const { return bAbsSpaces; }
void SetAbsSpaces( BOOL bFlag ) { bAbsSpaces = bFlag; }
// #115901#
BOOL IsOutlineRule() const { return eRuleType == OUTLINE_RULE; }
// erfragen und setzen der Poolvorlagen-Id's
USHORT GetPoolFmtId() const { return nPoolFmtId; }
void SetPoolFmtId( USHORT nId ) { nPoolFmtId = nId; }
// erfragen und setzen der Hilfe-Id's fuer die Document-Vorlagen
USHORT GetPoolHelpId() const { return nPoolHelpId; }
void SetPoolHelpId( USHORT nId ) { nPoolHelpId = nId; }
BYTE GetPoolHlpFileId() const { return nPoolHlpFileId; }
void SetPoolHlpFileId( BYTE nId ) { nPoolHlpFileId = nId; }
/**
#109308# Sets adjustment in all formats of the numbering rule.
@param eNum adjustment to be set
*/
void SetNumAdjust(SvxAdjust eNum);
void SetSvxRule(const SvxNumRule&, SwDoc* pDoc);
SvxNumRule MakeSvxNumRule() const;
// -> #i27615#
/**
Returns if a level is marked.
@param nLvl level to check
@retval TRUE level is marked
@retval FALSE level is not marked
*/
BOOL IsLevelMarked(BYTE nLvl) const { return aMarkedLevels.Get(nLvl); }
/**
Mark/unmark a level.
@param nLvl level to mark/unmark
@param bVal - TRUE mark
- FALSE unmark
@return bit array in which the altered levels are marked.
*/
SwBitArray SetLevelMarked(BYTE nLvl, BOOL bVal);
/**
Unmarks all levels.
*/
void ResetMarkedLevels() { aMarkedLevels.Reset(); }
// <- #i27615#
// #i23726#, #i23725#
void Indent(short aAmount, int nLevel = -1,
int nReferenceLevel = -1, BOOL bRelative = TRUE,
BOOL bFirstLine = TRUE, BOOL bCheckGtZero = TRUE);
};
class SW_DLLPUBLIC SwNodeNum
{
#ifndef PRODUCT
static long nSerial;
long nMySerial;
#endif
USHORT nLevelVal[ MAXLEVEL ]; // Nummern aller Levels
USHORT nSetValue; // vorgegeben Nummer
BYTE nMyLevel; // akt. Level
BOOL bStartNum; // Numerierung neu starten
BOOL bContNum; // #111955#
// TRUE -> in continuous numbering
public:
SwNodeNum( BYTE nLevel = NO_NUMBERING, USHORT nSetVal = USHRT_MAX );
SwNodeNum& operator=( const SwNodeNum& rCpy );
BOOL operator==( const SwNodeNum& ) const;
BYTE GetLevel() const { return nMyLevel; }
void SetLevel( BYTE nVal ) { ::SetLevel(&nMyLevel, nVal); }
BOOL IsStart() const { return bStartNum; }
void SetStart( BOOL bFlag = TRUE ) { bStartNum = bFlag; }
// -> #111955#
BOOL IsContinuousNum() const { return bContNum; }
void SetContinuousNum( BOOL bFlag = TRUE ) { bContNum = bFlag; }
// <- #111955#
BOOL HasSetValue() const { return USHRT_MAX != nSetValue; }
USHORT GetSetValue() const { return nSetValue; }
void SetSetValue( USHORT nVal ) { nSetValue = nVal; }
const USHORT* GetLevelVal() const { return nLevelVal; }
USHORT* GetLevelVal() { return nLevelVal; }
BYTE GetRealLevel() const { return ::GetRealLevel(nMyLevel); }
BOOL IsNum() const { return ::IsNum(nMyLevel); }
BOOL IsShowNum() const { return ::IsShowNum(nMyLevel); }
void SetNoNum(BOOL nVal = TRUE)
{
nMyLevel = nVal ? nMyLevel | NO_NUMLEVEL : nMyLevel & ~NO_NUMLEVEL;
}
};
sal_Unicode GetBulletChar(BYTE nLevel);
#endif // _NUMRULE_HXX
<commit_msg>INTEGRATION: CWS swnum03 (1.23.214); FILE MERGED 2005/07/05 08:42:55 hbrinkm 1.23.214.1: #i51566# instance counter and serial number for SwNumRule<commit_after>/*************************************************************************
*
* $RCSfile: numrule.hxx,v $
*
* $Revision: 1.24 $
*
* last change: $Author: obo $ $Date: 2005-07-18 13:33:42 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef _NUMRULE_HXX
#define _NUMRULE_HXX
#ifndef _LINK_HXX //autogen
#include <tools/link.hxx>
#endif
#ifndef _SV_GEN_HXX //autogen wg. Size
#include <tools/gen.hxx>
#endif
#ifndef _STRING_HXX //autogen
#include <tools/string.hxx>
#endif
#ifndef _SVX_SVXENUM_HXX //autogen
#include <svx/svxenum.hxx>
#endif
#ifndef _SVX_NUMITEM_HXX
#include <svx/numitem.hxx>
#endif
#ifndef INCLUDED_SWDLLAPI_H
#include "swdllapi.h"
#endif
#ifndef _SWTYPES_HXX
#include <swtypes.hxx>
#endif
#ifndef _CALBCK_HXX
#include <calbck.hxx>
#endif
#ifndef _ERRHDL_HXX
#include <errhdl.hxx> // Fuer die inline-ASSERTs
#endif
#ifndef _SWERROR_H
#include <error.h> // Fuer die inline-ASSERTs
#endif
#ifndef _SW_BIT_ARRAY_HXX
#include <SwBitArray.hxx> // #i27615#
#endif
#ifndef _HINTS_HXX
#include <hints.hxx>
#endif
#include <hash_map>
#include <stringhash.hxx>
class Font;
class SvxBrushItem;
class SvxNumRule;
class SwCharFmt;
class SwDoc;
class SwFmtVertOrient;
class SwNodeNum;
class SwTxtNode;
extern char __FAR_DATA sOutlineStr[]; // SWG-Filter
BYTE SW_DLLPUBLIC GetRealLevel( const BYTE nLvl );
BOOL SW_DLLPUBLIC IsNum( BYTE nLvl );
BOOL SW_DLLPUBLIC IsShowNum( BYTE nLvl );
void SW_DLLPUBLIC SetNoNum( BYTE * nLvl, BOOL nVal = TRUE );
void SW_DLLPUBLIC SetLevel( BYTE * nLvl, BYTE nNewLvl);
const sal_Unicode cBulletChar = 0x2022; // Charakter fuer Aufzaehlungen
class SW_DLLPUBLIC SwNumFmt : public SvxNumberFormat, public SwClient
{
SwFmtVertOrient* pVertOrient;
SW_DLLPRIVATE void UpdateNumNodes( SwDoc* pDoc );
SW_DLLPRIVATE virtual void NotifyGraphicArrived();
public:
SwNumFmt();
SwNumFmt( const SwNumFmt& );
SwNumFmt( const SvxNumberFormat&, SwDoc* pDoc);
virtual ~SwNumFmt();
SwNumFmt& operator=( const SwNumFmt& );
BOOL operator==( const SwNumFmt& ) const;
BOOL operator!=( const SwNumFmt& r ) const { return !(*this == r); }
const Graphic* GetGraphic() const;
SwCharFmt* GetCharFmt() const { return (SwCharFmt*)pRegisteredIn; }
void SetCharFmt( SwCharFmt* );
virtual void Modify( SfxPoolItem* pOld, SfxPoolItem* pNew );
virtual void SetCharFmtName(const String& rSet);
virtual const String& GetCharFmtName()const;
virtual void SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize = 0, const SvxFrameVertOrient* pOrient = 0);
virtual void SetVertOrient(SvxFrameVertOrient eSet);
virtual SvxFrameVertOrient GetVertOrient() const;
const SwFmtVertOrient* GetGraphicOrientation() const;
BOOL IsEnumeration() const; // #i22362#
BOOL IsItemize() const; // #i29560#
};
enum SwNumRuleType { OUTLINE_RULE = 0, NUM_RULE = 1, RULE_END = 2 };
class SW_DLLPUBLIC SwNumRule
{
friend void _FinitCore();
#ifndef PRODUCT
long int nSerial;
static long int nInstances;
#endif
static SwNumFmt* aBaseFmts [ RULE_END ][ MAXLEVEL ];
static USHORT aDefNumIndents[ MAXLEVEL ];
static USHORT nRefCount;
static Font* pDefBulletFont;
static char* pDefOutlineName;
SwNumFmt* aFmts[ MAXLEVEL ];
/**
cache for associated text nodes
*/
SwTxtNodeTable * pList;
/**
marked levels
*/
SwBitArray aMarkedLevels;
// #i36749#
/**
hash_map containing "name->rule" relation
*/
std::hash_map<String, SwNumRule *, StringHash> * pNumRuleMap;
String sName;
SwNumRuleType eRuleType;
USHORT nPoolFmtId; // Id-fuer "automatich" erzeugte NumRules
USHORT nPoolHelpId; // HelpId fuer diese Pool-Vorlage
BYTE nPoolHlpFileId; // FilePos ans Doc auf die Vorlagen-Hilfen
BOOL bAutoRuleFlag : 1;
BOOL bInvalidRuleFlag : 1;
BOOL bContinusNum : 1; // Fortlaufende Numerierung - ohne Ebenen
BOOL bAbsSpaces : 1; // die Ebenen repraesentieren absol. Einzuege
SW_DLLPRIVATE static void _MakeDefBulletFont();
// forbidden and not implemented.
SwNumRule();
public:
// single argument constructors shall be explicit.
explicit SwNumRule( const String& rNm, SwNumRuleType = NUM_RULE,
BOOL bAutoFlg = TRUE );
SwNumRule( const SwNumRule& );
~SwNumRule();
SwNumRule& operator=( const SwNumRule& );
BOOL operator==( const SwNumRule& ) const;
BOOL operator!=( const SwNumRule& r ) const { return !(*this == r); }
const SwNumFmt* GetNumFmt( USHORT i ) const;
const SwNumFmt& Get( USHORT i ) const;
void Set( USHORT i, const SwNumFmt* );
void Set( USHORT i, const SwNumFmt& );
String MakeNumString( const SwNodeNum&, BOOL bInclStrings = TRUE,
BOOL bOnlyArabic = FALSE ) const;
/**
Returns list of associated text nodes.
@return list of associated text nodes, or NULL if none present
*/
const SwTxtNodeTable * GetList() const { return pList; }
/**
Set list of associated text nodes.
@param _pList the list of associated text nodes
*/
void SetList(SwTxtNodeTable * _pList);
// #i36749#
/**
Register this rule in a "name->numrule" map.
@param pNumRuleMap map to register in
*/
void SetNumRuleMap(std::hash_map<String, SwNumRule *, StringHash> *
pNumRuleMap);
static const Font& GetDefBulletFont();
static char* GetOutlineRuleName() { return pDefOutlineName; }
static USHORT GetNumIndent( BYTE nLvl );
static USHORT GetBullIndent( BYTE nLvl );
SwNumRuleType GetRuleType() const { return eRuleType; }
void SetRuleType( SwNumRuleType eNew ) { eRuleType = eNew;
bInvalidRuleFlag = TRUE; }
// eine Art Copy-Constructor, damit die Num-Formate auch an den
// richtigen CharFormaten eines Dokumentes haengen !!
// (Kopiert die NumFormate und returnt sich selbst)
SwNumRule& CopyNumRule( SwDoc*, const SwNumRule& );
// testet ob die CharFormate aus dem angegeben Doc sind und kopiert
// die gegebenfalls
void CheckCharFmts( SwDoc* pDoc );
#ifndef NUM_RELSPACE
// test ob der Einzug von dieser Numerierung kommt.
BOOL IsRuleLSpace( SwTxtNode& rNd ) const;
#endif
const String& GetName() const { return sName; }
void SetName( const String& rNm ); // #i36749#
BOOL IsAutoRule() const { return bAutoRuleFlag; }
void SetAutoRule( BOOL bFlag ) { bAutoRuleFlag = bFlag; }
BOOL IsInvalidRule() const { return bInvalidRuleFlag; }
void SetInvalidRule( BOOL bFlag );
BOOL IsContinusNum() const { return bContinusNum; }
void SetContinusNum( BOOL bFlag ) { bContinusNum = bFlag; }
BOOL IsAbsSpaces() const { return bAbsSpaces; }
void SetAbsSpaces( BOOL bFlag ) { bAbsSpaces = bFlag; }
// #115901#
BOOL IsOutlineRule() const { return eRuleType == OUTLINE_RULE; }
// erfragen und setzen der Poolvorlagen-Id's
USHORT GetPoolFmtId() const { return nPoolFmtId; }
void SetPoolFmtId( USHORT nId ) { nPoolFmtId = nId; }
// erfragen und setzen der Hilfe-Id's fuer die Document-Vorlagen
USHORT GetPoolHelpId() const { return nPoolHelpId; }
void SetPoolHelpId( USHORT nId ) { nPoolHelpId = nId; }
BYTE GetPoolHlpFileId() const { return nPoolHlpFileId; }
void SetPoolHlpFileId( BYTE nId ) { nPoolHlpFileId = nId; }
/**
#109308# Sets adjustment in all formats of the numbering rule.
@param eNum adjustment to be set
*/
void SetNumAdjust(SvxAdjust eNum);
void SetSvxRule(const SvxNumRule&, SwDoc* pDoc);
SvxNumRule MakeSvxNumRule() const;
// -> #i27615#
/**
Returns if a level is marked.
@param nLvl level to check
@retval TRUE level is marked
@retval FALSE level is not marked
*/
BOOL IsLevelMarked(BYTE nLvl) const { return aMarkedLevels.Get(nLvl); }
/**
Mark/unmark a level.
@param nLvl level to mark/unmark
@param bVal - TRUE mark
- FALSE unmark
@return bit array in which the altered levels are marked.
*/
SwBitArray SetLevelMarked(BYTE nLvl, BOOL bVal);
/**
Unmarks all levels.
*/
void ResetMarkedLevels() { aMarkedLevels.Reset(); }
// <- #i27615#
// #i23726#, #i23725#
void Indent(short aAmount, int nLevel = -1,
int nReferenceLevel = -1, BOOL bRelative = TRUE,
BOOL bFirstLine = TRUE, BOOL bCheckGtZero = TRUE);
};
class SW_DLLPUBLIC SwNodeNum
{
#ifndef PRODUCT
static long nSerial;
long nMySerial;
#endif
USHORT nLevelVal[ MAXLEVEL ]; // Nummern aller Levels
USHORT nSetValue; // vorgegeben Nummer
BYTE nMyLevel; // akt. Level
BOOL bStartNum; // Numerierung neu starten
BOOL bContNum; // #111955#
// TRUE -> in continuous numbering
public:
SwNodeNum( BYTE nLevel = NO_NUMBERING, USHORT nSetVal = USHRT_MAX );
SwNodeNum& operator=( const SwNodeNum& rCpy );
BOOL operator==( const SwNodeNum& ) const;
BYTE GetLevel() const { return nMyLevel; }
void SetLevel( BYTE nVal ) { ::SetLevel(&nMyLevel, nVal); }
BOOL IsStart() const { return bStartNum; }
void SetStart( BOOL bFlag = TRUE ) { bStartNum = bFlag; }
// -> #111955#
BOOL IsContinuousNum() const { return bContNum; }
void SetContinuousNum( BOOL bFlag = TRUE ) { bContNum = bFlag; }
// <- #111955#
BOOL HasSetValue() const { return USHRT_MAX != nSetValue; }
USHORT GetSetValue() const { return nSetValue; }
void SetSetValue( USHORT nVal ) { nSetValue = nVal; }
const USHORT* GetLevelVal() const { return nLevelVal; }
USHORT* GetLevelVal() { return nLevelVal; }
BYTE GetRealLevel() const { return ::GetRealLevel(nMyLevel); }
BOOL IsNum() const { return ::IsNum(nMyLevel); }
BOOL IsShowNum() const { return ::IsShowNum(nMyLevel); }
void SetNoNum(BOOL nVal = TRUE)
{
nMyLevel = nVal ? nMyLevel | NO_NUMLEVEL : nMyLevel & ~NO_NUMLEVEL;
}
};
sal_Unicode GetBulletChar(BYTE nLevel);
#endif // _NUMRULE_HXX
<|endoftext|> |
<commit_before>/*****************************************************************************
* Licensed to Qualys, Inc. (QUALYS) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* QUALYS licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
****************************************************************************/
/**
* @file
* @brief Predicate --- Eval Implementation
*
* @author Christopher Alfeld <calfeld@qualys.com>
*/
// Define EVAL_TRACE to output information to cout at beginning and end
// of every eval() call.
//#define EVAL_TRACE
#include <ironbee/predicate/eval.hpp>
#include <ironbee/rule_engine.h>
using namespace std;
namespace IronBee {
namespace Predicate {
namespace {
static IronBee::ScopedMemoryPoolLite c_static_pool;
static const Value
c_empty_string(
IronBee::Field::create_byte_string(
c_static_pool,
"", 0,
IronBee::ByteString::create(c_static_pool)
)
);
}
// NodeEvalState
NodeEvalState::NodeEvalState() :
m_finished(false),
m_phase(IB_PHASE_NONE)
{
// nop
}
void NodeEvalState::forward(const node_p& to)
{
if (is_forwarding()) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't forward a forwarded node."
)
);
}
if (is_aliased()) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't forward an aliased node."
)
);
}
if (is_finished()) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't finish an already finished node."
)
);
}
if (m_local_values) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't combine existing values with local values."
)
);
}
m_forward = to;
}
void NodeEvalState::set_phase(ib_rule_phase_num_t phase)
{
m_phase = phase;
}
void NodeEvalState::setup_local_list(MemoryManager mm)
{
return setup_local_list(mm, "", 0);
}
void NodeEvalState::setup_local_list(
MemoryManager mm,
const char* name,
size_t name_length
)
{
if (is_aliased()) {
BOOST_THROW_EXCEPTION(
einval() << errinfo_what(
"Cannot setup local values on aliased node."
)
);
}
if (is_forwarding()) {
BOOST_THROW_EXCEPTION(
einval() << errinfo_what(
"Cannot setup local values on forwarded node."
)
);
}
if (m_value) {
// do nothing
return;
}
m_local_values = List<Value>::create(mm);
m_value = Value::alias_list(mm, name, name_length, m_local_values);
}
void NodeEvalState::append_to_list(Value value)
{
if (is_forwarding()) {
BOOST_THROW_EXCEPTION(
einval() << errinfo_what(
"Can't add value to forwarded node."
)
);
}
if (is_finished()) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't add value to finished node."
)
);
}
if (! m_local_values) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Attempting to add value before setting up local list."
)
);
}
m_local_values.push_back(value);
}
void NodeEvalState::finish()
{
if (is_forwarding()) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't finish a forwarded node."
)
);
}
if (is_finished()) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't finish an already finished node."
)
);
}
m_finished = true;
}
void NodeEvalState::finish(Value v)
{
if (m_value) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't finish a valued node with a value."
)
);
}
// Call finish first to do normal finish checks.
finish();
m_value = v;
}
void NodeEvalState::alias(Value other)
{
if (is_forwarding()) {
BOOST_THROW_EXCEPTION(
einval() << errinfo_what(
"Can't alias a forwarded node."
)
);
}
if (is_finished()) {
BOOST_THROW_EXCEPTION(
einval() << errinfo_what(
"Can't alias a finished node."
)
);
}
if (m_local_values) {
BOOST_THROW_EXCEPTION(
einval() << errinfo_what(
"Can't alias a local valued node."
)
);
}
if (m_value) {
BOOST_THROW_EXCEPTION(
einval() << errinfo_what(
"Can't alias an aliased node."
)
);
}
m_value = other;
}
void NodeEvalState::finish_true(EvalContext eval_context)
{
finish(c_empty_string);
}
// GraphEvalProfileData
void GraphEvalProfileData::mark_start() {
m_eval_start = ib_clock_get_time();
}
void GraphEvalProfileData::mark_finish() {
m_eval_finish = ib_clock_get_time();
}
uint32_t GraphEvalProfileData::duration() const {
return (m_eval_finish - m_eval_start);
}
// GraphEvalState
GraphEvalState::GraphEvalState(size_t index_limit) :
m_vector(index_limit),
m_profile(false)
{
// nop
}
const NodeEvalState& GraphEvalState::final(size_t index) const
{
while (m_vector[index].is_forwarding()) {
index = m_vector[index].forwarded_to()->index();
}
return m_vector[index];
}
Value GraphEvalState::value(size_t index) const
{
return final(index).value();
}
ib_rule_phase_num_t GraphEvalState::phase(size_t index) const
{
return final(index).phase();
}
bool GraphEvalState::is_finished(size_t index) const
{
return final(index).is_finished();
}
void GraphEvalState::initialize(const node_cp& node, EvalContext context)
{
assert(! m_vector[node->index()].is_forwarding());
node->eval_initialize(*this, context);
}
void GraphEvalState::eval(const node_cp& node, EvalContext context)
{
#ifdef EVAL_TRACE
cout << "EVAL " << node->to_s() << endl;
#endif
// In certain cases, e.g., literals, we run without a context or
// rule_exec. Then, always calculate.
ib_rule_phase_num_t phase = IB_PHASE_NONE;
if (context.ib() && context.ib()->rule_exec) {
phase = context.ib()->rule_exec->phase;
}
// Handle forwarding.
node_cp final_node = node;
while (m_vector[final_node->index()].is_forwarding()) {
final_node = m_vector[final_node->index()].forwarded_to();
}
NodeEvalState& node_eval_state = m_vector[final_node->index()];
assert(! node_eval_state.is_forwarding());
if (
! node_eval_state.is_finished() &&
(node_eval_state.phase() != phase || phase == IB_PHASE_NONE)
) {
if (m_profile) {
GraphEvalProfileData& gpd = profiler_mark(final_node);
node_eval_state.set_phase(phase);
final_node->eval_calculate(*this, context);
profiler_record(gpd);
}
else {
node_eval_state.set_phase(phase);
final_node->eval_calculate(*this, context);
}
}
#ifdef EVAL_TRACE
cout << "VALUE " << node->to_s() << " = " << value(node->index()) << endl;
#endif
}
GraphEvalProfileData::GraphEvalProfileData(const std::string& name)
:
m_node_name(name),
m_eval_start(0),
m_eval_finish(0)
{
}
GraphEvalProfileData& GraphEvalState::profiler_mark(node_cp node)
{
GraphEvalProfileData data(node->to_s());
data.mark_start();
m_profile_data.push_back(data);
return m_profile_data.back();
}
void GraphEvalState::profiler_record(GraphEvalProfileData& data)
{
data.mark_finish();
}
GraphEvalState::profiler_data_list_t& GraphEvalState::profiler_data()
{
return m_profile_data;
}
const GraphEvalState::profiler_data_list_t&
GraphEvalState::profiler_data() const
{
return m_profile_data;
}
void GraphEvalState::profiler_clear()
{
m_profile_data.clear();
}
void GraphEvalState::profiler_enabled(bool enabled)
{
m_profile = enabled;
}
// Doxygen confused by this code.
#ifndef DOXYGEN_SKIP
namespace Impl {
make_indexer_helper_t::make_indexer_helper_t(size_t& index_limit) :
m_index_limit(index_limit)
{
// nop
}
void make_indexer_helper_t::operator()(const node_p& node)
{
node->set_index(m_index_limit);
++m_index_limit;
}
make_initializer_helper_t::make_initializer_helper_t(
GraphEvalState& graph_eval_state,
EvalContext context
) :
m_graph_eval_state(graph_eval_state),
m_context(context)
{
// nop
}
void make_initializer_helper_t::operator()(const node_cp& node)
{
m_graph_eval_state.initialize(node, m_context);
}
}
#endif
boost::function_output_iterator<Impl::make_indexer_helper_t>
make_indexer(size_t& index_limit)
{
index_limit = 0;
return boost::function_output_iterator<Impl::make_indexer_helper_t>(
Impl::make_indexer_helper_t(index_limit)
);
}
boost::function_output_iterator<Impl::make_initializer_helper_t>
make_initializer(GraphEvalState& graph_eval_state, EvalContext context)
{
return boost::function_output_iterator<Impl::make_initializer_helper_t>(
Impl::make_initializer_helper_t(graph_eval_state, context)
);
}
} // Predicate
} // IronBee
<commit_msg>eval.cpp: Adding a profiling check of initialization time.<commit_after>/*****************************************************************************
* Licensed to Qualys, Inc. (QUALYS) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* QUALYS licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
****************************************************************************/
/**
* @file
* @brief Predicate --- Eval Implementation
*
* @author Christopher Alfeld <calfeld@qualys.com>
*/
// Define EVAL_TRACE to output information to cout at beginning and end
// of every eval() call.
//#define EVAL_TRACE
#include <ironbee/predicate/eval.hpp>
#include <ironbee/rule_engine.h>
using namespace std;
namespace IronBee {
namespace Predicate {
namespace {
static IronBee::ScopedMemoryPoolLite c_static_pool;
static const Value
c_empty_string(
IronBee::Field::create_byte_string(
c_static_pool,
"", 0,
IronBee::ByteString::create(c_static_pool)
)
);
}
// NodeEvalState
NodeEvalState::NodeEvalState() :
m_finished(false),
m_phase(IB_PHASE_NONE)
{
// nop
}
void NodeEvalState::forward(const node_p& to)
{
if (is_forwarding()) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't forward a forwarded node."
)
);
}
if (is_aliased()) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't forward an aliased node."
)
);
}
if (is_finished()) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't finish an already finished node."
)
);
}
if (m_local_values) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't combine existing values with local values."
)
);
}
m_forward = to;
}
void NodeEvalState::set_phase(ib_rule_phase_num_t phase)
{
m_phase = phase;
}
void NodeEvalState::setup_local_list(MemoryManager mm)
{
return setup_local_list(mm, "", 0);
}
void NodeEvalState::setup_local_list(
MemoryManager mm,
const char* name,
size_t name_length
)
{
if (is_aliased()) {
BOOST_THROW_EXCEPTION(
einval() << errinfo_what(
"Cannot setup local values on aliased node."
)
);
}
if (is_forwarding()) {
BOOST_THROW_EXCEPTION(
einval() << errinfo_what(
"Cannot setup local values on forwarded node."
)
);
}
if (m_value) {
// do nothing
return;
}
m_local_values = List<Value>::create(mm);
m_value = Value::alias_list(mm, name, name_length, m_local_values);
}
void NodeEvalState::append_to_list(Value value)
{
if (is_forwarding()) {
BOOST_THROW_EXCEPTION(
einval() << errinfo_what(
"Can't add value to forwarded node."
)
);
}
if (is_finished()) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't add value to finished node."
)
);
}
if (! m_local_values) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Attempting to add value before setting up local list."
)
);
}
m_local_values.push_back(value);
}
void NodeEvalState::finish()
{
if (is_forwarding()) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't finish a forwarded node."
)
);
}
if (is_finished()) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't finish an already finished node."
)
);
}
m_finished = true;
}
void NodeEvalState::finish(Value v)
{
if (m_value) {
BOOST_THROW_EXCEPTION(
IronBee::einval() << errinfo_what(
"Can't finish a valued node with a value."
)
);
}
// Call finish first to do normal finish checks.
finish();
m_value = v;
}
void NodeEvalState::alias(Value other)
{
if (is_forwarding()) {
BOOST_THROW_EXCEPTION(
einval() << errinfo_what(
"Can't alias a forwarded node."
)
);
}
if (is_finished()) {
BOOST_THROW_EXCEPTION(
einval() << errinfo_what(
"Can't alias a finished node."
)
);
}
if (m_local_values) {
BOOST_THROW_EXCEPTION(
einval() << errinfo_what(
"Can't alias a local valued node."
)
);
}
if (m_value) {
BOOST_THROW_EXCEPTION(
einval() << errinfo_what(
"Can't alias an aliased node."
)
);
}
m_value = other;
}
void NodeEvalState::finish_true(EvalContext eval_context)
{
finish(c_empty_string);
}
// GraphEvalProfileData
void GraphEvalProfileData::mark_start() {
m_eval_start = ib_clock_get_time();
}
void GraphEvalProfileData::mark_finish() {
m_eval_finish = ib_clock_get_time();
}
uint32_t GraphEvalProfileData::duration() const {
return (m_eval_finish - m_eval_start);
}
// GraphEvalState
GraphEvalState::GraphEvalState(size_t index_limit) :
m_vector(index_limit),
m_profile(false)
{
// nop
}
const NodeEvalState& GraphEvalState::final(size_t index) const
{
while (m_vector[index].is_forwarding()) {
index = m_vector[index].forwarded_to()->index();
}
return m_vector[index];
}
Value GraphEvalState::value(size_t index) const
{
return final(index).value();
}
ib_rule_phase_num_t GraphEvalState::phase(size_t index) const
{
return final(index).phase();
}
bool GraphEvalState::is_finished(size_t index) const
{
return final(index).is_finished();
}
void GraphEvalState::initialize(const node_cp& node, EvalContext context)
{
assert(! m_vector[node->index()].is_forwarding());
if (m_profile) {
GraphEvalProfileData& gpd = profiler_mark(node);
node->eval_initialize(*this, context);
profiler_record(gpd);
}
else {
node->eval_initialize(*this, context);
}
}
void GraphEvalState::eval(const node_cp& node, EvalContext context)
{
#ifdef EVAL_TRACE
cout << "EVAL " << node->to_s() << endl;
#endif
// In certain cases, e.g., literals, we run without a context or
// rule_exec. Then, always calculate.
ib_rule_phase_num_t phase = IB_PHASE_NONE;
if (context.ib() && context.ib()->rule_exec) {
phase = context.ib()->rule_exec->phase;
}
// Handle forwarding.
node_cp final_node = node;
while (m_vector[final_node->index()].is_forwarding()) {
final_node = m_vector[final_node->index()].forwarded_to();
}
NodeEvalState& node_eval_state = m_vector[final_node->index()];
assert(! node_eval_state.is_forwarding());
if (
! node_eval_state.is_finished() &&
(node_eval_state.phase() != phase || phase == IB_PHASE_NONE)
) {
if (m_profile) {
GraphEvalProfileData& gpd = profiler_mark(final_node);
node_eval_state.set_phase(phase);
final_node->eval_calculate(*this, context);
profiler_record(gpd);
}
else {
node_eval_state.set_phase(phase);
final_node->eval_calculate(*this, context);
}
}
#ifdef EVAL_TRACE
cout << "VALUE " << node->to_s() << " = " << value(node->index()) << endl;
#endif
}
GraphEvalProfileData::GraphEvalProfileData(const std::string& name)
:
m_node_name(name),
m_eval_start(0),
m_eval_finish(0)
{
}
GraphEvalProfileData& GraphEvalState::profiler_mark(node_cp node)
{
GraphEvalProfileData data(node->to_s());
data.mark_start();
m_profile_data.push_back(data);
return m_profile_data.back();
}
void GraphEvalState::profiler_record(GraphEvalProfileData& data)
{
data.mark_finish();
}
GraphEvalState::profiler_data_list_t& GraphEvalState::profiler_data()
{
return m_profile_data;
}
const GraphEvalState::profiler_data_list_t&
GraphEvalState::profiler_data() const
{
return m_profile_data;
}
void GraphEvalState::profiler_clear()
{
m_profile_data.clear();
}
void GraphEvalState::profiler_enabled(bool enabled)
{
m_profile = enabled;
}
// Doxygen confused by this code.
#ifndef DOXYGEN_SKIP
namespace Impl {
make_indexer_helper_t::make_indexer_helper_t(size_t& index_limit) :
m_index_limit(index_limit)
{
// nop
}
void make_indexer_helper_t::operator()(const node_p& node)
{
node->set_index(m_index_limit);
++m_index_limit;
}
make_initializer_helper_t::make_initializer_helper_t(
GraphEvalState& graph_eval_state,
EvalContext context
) :
m_graph_eval_state(graph_eval_state),
m_context(context)
{
// nop
}
void make_initializer_helper_t::operator()(const node_cp& node)
{
m_graph_eval_state.initialize(node, m_context);
}
}
#endif
boost::function_output_iterator<Impl::make_indexer_helper_t>
make_indexer(size_t& index_limit)
{
index_limit = 0;
return boost::function_output_iterator<Impl::make_indexer_helper_t>(
Impl::make_indexer_helper_t(index_limit)
);
}
boost::function_output_iterator<Impl::make_initializer_helper_t>
make_initializer(GraphEvalState& graph_eval_state, EvalContext context)
{
return boost::function_output_iterator<Impl::make_initializer_helper_t>(
Impl::make_initializer_helper_t(graph_eval_state, context)
);
}
} // Predicate
} // IronBee
<|endoftext|> |
<commit_before>#include<cmath>
bool isPrimeBruteForce(int x) {
if (x < 2)
return false;
float sqroot_x = sqrt(x);
for(int i=0; i <= sqroot_x; i++) { /* If there were only factors above the square root of x, they would be bigger than x itself. */
if (x%i==0)
return false;
}
return true;
}
int main(int argc, char* argv[])
{
/* call isPrimeBruteForce with argument given to the program as x */
return 0;
}
<commit_msg>Update primality-test.cpp<commit_after>#include<cmath>
#include<iostream>
using namespace std;
bool isPrimeBruteForce(int x)
{
if (x < 2)
return false;
float sqroot_x = sqrt(x);
for(int i=0; i <= sqroot_x; i++) { /* If there were only factors above the square root of x, they would be bigger than x itself. */
if (x%i==0)
return false;
}
return true;
}
int main(int argc, char* argv[])
{
int number;
bool result;
cout << "Enter number to test if it's prime: ";
cin >> number;
result = isPrimeBruteForce(number);
if result {
cout << number << " is a prime number.";
} else {
cout << number << " is not a prime number.";
}
return 0;
}
<|endoftext|> |
<commit_before><commit_msg>Summary: Rotate_8U crash fixed(Bug no 1913329) Reviewer: kalyan, pass<commit_after><|endoftext|> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.